|
8:16:45 PM |
|
Quick Tip: Keeping unit tests in parallel source trees
It's common practise to bundle unit-tests in the same source tree as production code. To distinguish between test code and production code, tests are placed in a subpackage called test. src/com/blah/thing/Cheese.java src/com/blah/thing/Thing.java src/com/blah/thing/test/CheeseTest.java src/com/blah/thing/test/ThingTest.java src/com/blah/another/Cow.java src/com/blah/another/test/CowTest.java
However, if tests are kept in parallel source trees and the test subpackage is ditched, it gives some useful advantages:
- Because the test cases now reside in the same package, members with package protection can be accessed from the tests. This is an easy compromise for testing the internals of classes without making their members public.
- Production code can be compiled easily in isolation from the test code, ensuring there no unwanted dependencies.
- It's easy to generate things like API documentation and release packages without including tests.
src/java/com/blah/thing/Cheese.java src/java/com/blah/thing/Thing.java src/java/com/blah/another/Cow.java src/test/com/blah/thing/CheeseTest.java src/test/com/blah/thing/ThingTest.java src/test/com/blah/another/CowTest.java
|