Unit Test performs white-box testing on source code modules -- usually at the class level. The unit tests are implemented using the jUnit unit testing framework. The unit test cases are required to measure the functional quality of the coding as far upstream as possible. The unit tests are completely automated. The unit tests are generated by developers concurrently with their production code.
The ant build script can be used to run the unit tests. It runs the umich.cac.test.AllUnitTests unit test suite. To run the tests type
ant runtestsin the top level directory where the build.xml file is located
The unit test cases reside in a test sub-package of the package the unit test refers to. For example, unit tests for the umich.cac.util package (located in the .../umich/cac/util directory) will reside in the umich.cac.util.test package (located in the .../umich/cac/util/test directory.) The unit test classes have to belong to a different package than their production class counterparts so that they better mimic client code and so that the unit test classes are not included in the jar files.
New unit test case for each new Java class (except abstract classes and interfaces.)
New unit test case for each existing Java class that is to be modified/enhanced. The new test case will baseline the existing code to ensure that you do not unintentionally break anything. The new test case will verify the added/modified functionality.
New "AllTests" unit test case suite for each unit test package. The "AllTests" suite has to be manually updated when further unit test cases are added to its package.
"AllUnitTests" unit test case suite in umich.cac.test that runs all of the "AllTests" suites located in the other test packages. The "AllUnitTests" suite has to be manually updated when further "AllTests" classes are added to new test packages.
Create the Java class for the unit test:
Create a class called XxxTest inherited from junit.framework.TestCase where Xxx is the name of the production class this test case is testing
Place the class in the test sub-package of package the production class resides in
Add constructor taking "String name" parameter
Add "public static Test suite()" method
Add test methods named "public void testX()" where X is a public method in the production class
Add the test case to the suites:
Add XxxTest.suite() to the local AllTests class if it is not already present
Add AllTests.suite() to umich.cac.test.AllUnitTests class if it is not already present
The unit test case will:
demonstrate capability of the production class (all public methods)
demonstrate intentional failures in the production class (expected exceptions, expected error codes, etc.)
The unit test case will not:
be dependent on other tests
be required to run in a certain order
rely on databases or other network services being live (this is beyond unit testing scope and is handled by other tools)