In Java/Junit, I need to test for null with some object. There are a variety of ways I can test a condition but I have been using assertTrue for most of my tests. When I check for nulls in an assertTrue, EclEmma states that it is only testing one branch.
When I resolve the statement into a variable manually (like setting the result to a boolean and passing it into assertTrue) the code coverage is deemed complete on the assert but not on the variable initializing line.
Why is this happening? Is this related to the extra byte code that Java apparently adds as mentioned on http://sourceforge.net/apps/trac/eclemma/wiki/FilteringOptions? Any solutions (besides using other assert statements).
assertTrue:
assertTrue( myObject == null ); //1 of 2 branches
assertTrue:
boolean test = (myObject == null); //1 of 2 branches missing
assertTrue(test); // complete
assertNull:
assertNull( myObject ) //complete;