A Unit Testing Framework

As with all levels of software testing, unit testing requires that a supporting infrastructure be in place. The unit testing infrastructure must provide the information necessary to design unit tests and unit test data. It must also provide a repository where all unit testing artifacts (tests, test data, and test results) can be permanently stored. This infrastructure must also serve as a test harness for unit test execution, and it must capture and store the test results. ANSI/IEEE STD 1008-1987 defines unit testing and documents a formal unit testing approach (1).

Performing unit tests manually is time consuming and burdensome. This is why developers shy away from it. Of course, as with all endeavors, we develop shortcuts that allow us to do our work faster and better. This is true even for unit testing, which can be enhanced through the use of MS Excel and MS Word to document test data, etc. We have also seen Lotus Notes database used to document and store unit testing. The problem is the manual work required to update these databases, especially when doing unit-level regression testing. Overall, this leads to increased test data maintenance.

A more effective approach is to use tools that have been especially designed for unit testing. There are several commercially available products and several others that can be found free of charge on the Web. There are tools available that support commonly used programming environments such as Visual Basic, C, and Java. Many of the available tools instrument the source code and provide test coverage metrics.

Commercial tools vary in functionality. Some are extremely sophisticated. For instance, Rational Software's QualityArchitect can parse Java code and reverse engineer it into Rational Rose diagrams that it uses to construct test cases. This product also executes the test against the application and captures the results. On the other hand, there are tools that are very unsophisticated in terms of the features they provide, but yet are powerful tools. JUnit, which is freely distributed on the Web, is an excellent unit testing tool, but it places on the developer's shoulders the burden of designing, constructing, executing, and analyzing the tests. Once the initial test framework has been set up using JUnit, it does support unit-level regression testing. The difference between these two products is not in what they do as much as it is in the amount of effort required to implement them. The moral of the story is that you get what you pay for.

For Object-Oriented Development Using Java

Unit tests should be written from the developer's perspective and focus on particular methods of the class under test. When developing unit tests in an object-oriented environment, Canna has the following advice to offer: (3)

  • Write the unit test before writing code for the class it tests.

  • Capture code comments in unit tests.

  • Test all the public methods that perform an “interesting” function (that is, not getters and setters, unless they do their getting and setting in some unique way).

  • Put each test case in the same package as the class it's testing to gain access to package and protected members.

  • Avoid using domain-specific objects in unit tests.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.148.104.149