When should I use coverage tests?
There are many reasons to use coverage tests. Some of them are:
Does code coverage guarantee good test cases?
No, they only help a little. You can call a method, without asserting any conditions afterwards. A test like this covers the method, but does not help in any way. Mutation Testing is an interesting approach to this problem.
I think I achieved full code coverage, but Hansel still complains.
public boolean not(boolean b { return !b; }Is translated to:
0: iload_1 1: ifne #8 4: iconst_1 5: goto #9 8: iconst_0 9: ireturnWhile the java code can be covered by one invocation of the method, two invocations are needed to cover the bytecode.
I'm unable to cover a piece of code. What should I do?
This is hard to answer this in general. If you are absolutely sure that the code can never be executed: remove it ;) Often mock objects can help to test code, that is hard to cover otherwise. If you find code, that (you think) cannot be covered and should not be changed, please tell me.
Can I run multiple coverage tests concurrently?
I get a java.lang.reflect.InvocationTargetException. What happened?
java.lang.reflect.InvocationTargetException: java.lang.NoSuchMethodError at org.hansel.ModifyingClassLoader.You are using an old version of BCEL. Please use either the version distributed with Hansel, or a version more recent than 2002/05/10 (Currently only available through CVS). If you are using the jar distributed with Hansel, but still get the exception, there might be an old jar file in:(ModifyingClassLoader:35)
Why do some Exceptions seem to not get properly caught when using Hansel?
If the Exception was loaded by an instrumented class loader and the class catching it was not (or visa versa), the Exception will not be caught. The solution is to add the Exception's package to the excluded packages list. See here for more details on hansel and classloaders.
You probably ran into a problem caused by using different classloaders. See here for more details on hansel and classloaders.