Created
June 24, 2015 17:35
-
-
Save fourlastor/208c02bcf6e5945a2fe6 to your computer and use it in GitHub Desktop.
coverage
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
/* | |
* Original requirement: | |
* if a > b, return 1, if a == b return 0, if a < b return -1 | |
*/ | |
/* | |
* Day 1 | |
* Paul comes in and does untested code which has a bug | |
*/ | |
class UntestedClass { | |
public int compare(int a, int b) { | |
if (a > b) { | |
return -1; | |
} | |
if (a == b) { | |
return 0 | |
} | |
return 1; | |
} | |
} | |
/* | |
* Day 2 | |
* Nelson comes in and checks the code coverage. | |
* OH NOES! THERE ARE NO TESTS! | |
*/ | |
class UntestedClassTest { | |
private UntestedClass theClass = new UntestedClass(); | |
@Test | |
public void testAgtB throws Exception { | |
assertThat(theClass.compare(5, 3), is(-1)); | |
} | |
@Test | |
public void testAeqB throws Exception { | |
assertThat(theClass.compare(3, 3), is(0)); | |
} | |
@Test | |
public void testAltB throws Exception { | |
assertThat(theClass.compare(3, 5), is(1)); | |
} | |
} | |
// Now the code is covered, and the bug looks like a requirement for future developers... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment