Hi every body, 

Sorry if the question has already been posted, but I didn't found something 
similar.

I'm using Jacoco since few days and I've found some branches seems not possible 
to test => and Jacoco tells me that code is not 100% tested.


Let's imagine I've the following Enum : 

MyEnum {
     CASE1,
     CASE2,
     CASE3;
}


And a method to test :
public String doIt(MyEnum myEnum) throws Exception {
         switch (myEnum) {
         case CASE1:
                return "1";
                 break;
         
         case CASE2:
                return "2";
                 break;
         
         case CASE3
                return "3";
                 break;
         default:
                 // Here it's only to avoid warning in eclipse : 
                 // missing defaut case in switch...
                 throw new Exception("Unexpected Enum value: " + myEnum) ;
         }
}


I've written all unit tests possible (with all MyEnum values) but Jacoco said 
that my test is 75% tested. The reason is that default is never tested. 
But I've no idea how I can test it.

Calling doIt(null) will lead in a NullPointerException and does not resolve my 
problem.

I'm a little bit disapointed because I have to add default to avoid warnings 
and now I've have bad scoring test reports.

Is there a solution to enhance this ?
I expect the solution is not to relace switch by if...

Thanks 

-- 
You received this message because you are subscribed to the Google Groups 
"JaCoCo and EclEmma Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jacoco/ee6ca1f9-626e-4d26-bb0e-6bd3350ac3b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to