[Right]-BICEP: Are the Results Right?
Your tests should first and foremost validate that the code produces expected results. The arithmetic-mean test in Chapter 1, Building Your First JUnit Test demonstrates that the ScoreCollection class produces the correct mean of 6 given the numbers 5 and 7. We show it again here.
iloveyouboss/13/test/iloveyouboss/ScoreCollectionTest.java | |
| @Test |
| public void answersArithmeticMeanOfTwoNumbers() { |
| ScoreCollection collection = new ScoreCollection(); |
| collection.add(() -> 5); |
| collection.add(() -> 7); |
| |
| int actualResult = collection.arithmeticMean(); |
| |
| assertThat(actualResult, equalTo(6)); |
| } |
You might bolster such a test by adding more numbers to ScoreCollection or by trying larger numeric ...
Get Pragmatic Unit Testing in Java 8 with JUnit now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.