[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.

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 live online training, plus books, videos, and digital content from nearly 200 publishers.