Following the standard convention I keep my source code and unit tests in separate folders.
I follow the same package structure when creating the test.
For example, if there is a class OrderGenerator in package com.kshitiz in folder src my unit test would be OrderGeneratorTest in com.kshitiz in folder test.
In my current setup this type of organization becomes unmanageable after a while. I cannot write the unit tests before the code. Some other developer is responsible for writing the code and I am supposed to followup with test cases. (Yes I know it should be the other way around but I can’t help it)
Since the test cases are written second I must go through all the packages looking for classes and look for methods in those classes to ensure that I’ve got a test for them. With 100s of classes and 1000s of methods its quite painful.
Is there a way to make sure that your test case coverage is in line with the code? Is there a simple way to find the classes that don’t have a corresponding test case somewhere?
I am using Java, Eclipse and Junit 4.
EclEmma
Code coverage will tell you not only which classes are tested (directly or indirectly) by your tests but also which methods and within those, which branches are covered by your tests. It can be a really great guide to figure out where to spend early testing effort.
Here’s the kind of report it gives you:
You can see in the panel at the bottom right how much of each class is covered, so the class second from the bottom is hardly tested at all. At the top right, it shows which branches are covered — obviously that method has never been tested with empty inputs.