In order to get the full benefit from unit tests, the test suite should be run as partof the build process – this is what I mean by ‘automated’ unit tests. The buildalong with the unit tests should be scheduled to run automatically once or twice aday. If you have unit tests but do not run them as part of a scheduled build, thenyou are not getting the full benefit from the tests. By running the tests as part of a scheduled build, you test early and often. This again ensures that the sourcecode in the main repository remains healthy. In real life, developers mayaccidentally check in code that does not work. The daily build should be yourmain line of defense against these bugs. There are some wonderful and cheaptools for implementing build and test systems, e.g., if you are developing for.NET, you can use NAnt and NUnit frameworks. How to implement a build processis again a fairly large topic and resources on this site and elsewhere on the webcan get you started.Writing unit tests is an extra effort if compared to not writing tests at all, and thisshould not be ignored. In my experience writing unit tests adds roughly 10-30%to the time it takes to complete a feature. End-to-end tests tend to be the mosttime consuming type of tests to write. Then again, when writing end-to-end testsone usually very quickly creates a small framework as the common code in thetests is factored out. Thus writing end-to-end tests comes easier after the firstfew test cases have been written.Both types of tests - end-to-end and point tests – are needed for best coverage.End-to-end tests find different kinds of problems as they exercise a number of components that participate in the implementation of a feature. Point unit testsare also needed for the most important components because they can verify thefunctionality of a component more thoroughly.
Benefits of an Automated Unit Test Suite
An automated unit test suite brings along a number of important, tangibleadvantages as compared to other testing strategies.First,
unit tests find problems early in the development cycle
. The commonwisdom in software development is that the earlier problems are found, thecheaper it is to fix them. An automated unit test suite finds problems effectivelyas early as possible, long before the software reaches a customer, and evenbefore it reaches the QA team. Most of the problems in new code are alreadyuncovered before the developer checks the code into source control.Second,
an automated unit test suite watches over your code in twodimensions: time and space
. It watches over your code in the time dimensionbecause once you’ve written a unit test, it guarantees that the code you wroteworks now and in the future. It watches over your code in space dimensionbecause unit tests written for other features guarantee that your new code didnot break them; likewise it guarantees that code written for other features doesnot adversely affect the code you wrote for this feature.Third,
developers will be less afraid to change existing code
. Over time,software systems become more and more change resistant because developersare reluctant to change old code. This is natural because when changing old code,there is always the risk of breaking it or some other part of the system through aside-effect.
Leave a Comment