Last active
January 25, 2017 19:39
-
-
Save luisartola/bd49718d18f8e738c037be976ace0786 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import org.junit.Test; | |
import static org.junit.Assert.assertEquals; | |
public class ExampleTest { | |
/* | |
Sometimes(*) 100% line coverage is not enough | |
*/ | |
@Test | |
public void one_case_that_covers_all_the_lines() { | |
assertEquals("50.0 %", this.formattedPercentage(5, 10)); | |
} | |
private String formattedPercentage(double x, double y) { | |
return String.valueOf((x / y) * 100) + " %"; //if y == 0 it fails, no test covers this | |
} | |
} | |
-// (*) Achieving 100% coverage can be really hard. You need to think about the ROI (economic!) of the tests you are writing | |
-// Don´t think about "line coverage", think about 100% of input/output combination cases |
lluismf
commented
Jan 25, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment