Organizing the JUnit Tests in Your Project
There are many ways to address the need to organize your projects and the corresponding tests. We can place our tests in the same package and directory as the classes under testing, as we did in the examples. However, as your project grows, this is likely to clutter your source directory. If you need to later create jar files for your customers, it will require additional work on your part to prevent the packaging of unwanted test code.
There are three approaches that are often presented to organize these test cases: one creates a separate parallel directory structure with the same package alignment as the classes being tested (see Figure 7). The second creates a subpackage for all the test classes. And the third creates one TestCase class for a complete package. Irrespective of the approach you take, it is very crucial that all the tests are a part of your project build process. This ensures that the project and the tests do not get out of synch with each other during the life of the project.
Figure 7 Example of organization of the code for unit tests and the actual classes.