March 2015
Intermediate to advanced
236 pages
5h 26m
English
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 ...
Read now
Unlock full access