Reputation: 9200
I'm using EclEmma to test the coverage of the test class I have written (JUnit testing). I have enabled the assertions in Java using -ea
. After running the coverage test, where I have used Java assertions(in the actual code, not the test code of course), it says that that x
branches of y
missed. How can I cover all the branches? Is there something I'm doing wrong?
Upvotes: 1
Views: 4236
Reputation: 2295
I think you are asking why you get lower coverage when you disable your assertions? This happens because the compiler inserts new branches for asserts. Consider this example:
assert x > 0;
The compiler will insert code that corresponds roughly to
if (assertions are enabled) {
if ( ! x > 0 )
throw new AssertionViolatedException()
}
}
This adds branches to your code, and none of those are executed when you turn of assertions. That will drop your coverage ratio, but that's not big deal, as this refers to compiler generated code.
Upvotes: 2