[Right]-BICEP: Are the Results Right?

Learn if the tests we write give the correct results.

We'll cover the following

Our tests should first validate that the code produces the expected results. The arithmetic-mean test below demonstrates that the ScoreCollection class produces the correct mean of 6 given the numbers 5 and 7.

@Test
public void answersArithmeticMeanOfTwoNumbers() {
   ScoreCollection collection = new ScoreCollection();
   collection.add(() -> 5);
   collection.add(() -> 7);
   
   int actualResult = collection.arithmeticMean();
   
   assertThat(actualResult, equalTo(6));
}

Happy path test

  • We might bolster such a test by adding more numbers to ScoreCollection or by trying larger numeric values. Regardless, such tests remain in the realm of happy path tests—positive cases that reflect a portion of an end-user goal for the software (it could be a tiny portion!). If our code provides the right answer for these cases, the end-user will be happy.
  • A happy path test represents one answer to an important question:

Get hands-on with 1200+ tech skills courses.