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
EclEmma is a free Java code coverage tool for Eclipse, available under the Eclipse Public License. It brings code coverage analysis directly into the Eclipse workbench:
- Fast develop/test cycle: Launches from within the workbench like JUnit test runs can directly be analyzed for code coverage.
- Rich coverage analysis: Coverage results are immediately summarized and highlighted in the Java source code editors.
- Non-invasive: EclEmma does not require modifying your projects or performing any other setup.
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.
Depending on the nature of your project, you may be interested in Clover, also available as an eclipse plugin. More information at the Atlassian web-site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With