Created
October 25, 2011 11:13
-
-
Save virtix/1312340 to your computer and use it in GitHub Desktop.
Shows how statement coverage can be higher than branch coverage. This is an inverse subsumption relation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package test; | |
import static org.junit.Assert.*; | |
import org.junit.Test; | |
import junit.framework.TestCase; | |
public class CoverageTest { | |
/** | |
* | |
* Computes 100% statement coverage but 75% branch coverage. | |
* */ | |
@Test | |
public void testExists(){ | |
int[] a = {0,-1,1,100,99}; | |
int x = 99; | |
assertTrue( exists(x, a) ); | |
} | |
/** | |
* | |
* Our code under test. | |
* */ | |
public boolean exists(int x, int[] a){ | |
boolean ret = false; | |
for(int i=0; i < a.length; i++){ | |
if( x == a[i] ) { | |
ret = true; | |
break; | |
} | |
} | |
return ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Clover computes this as 100% statement coverage and 75% branch coverage. But Clover doesn't show "which" branch is not covered. I suspect it's the i < a.length condition.