March 2015
Intermediate to advanced
236 pages
5h 26m
English
In the prior section, we ran a test that does…nothing. Now it’s time to flesh it out with code that vets the ScoreCollection class.
We want to start with a scenario—a test case—that provides an example of expected behavior of the target code. To test a ScoreCollection object, we can add the numbers 5 and 7 to it and expect that the arithmeticMean method will return 6 (because (5 + 7) / 2 is equal to 6).
Naming is important. We call this test answersArithmeticMeanOfTwoNumbers—that nicely summarizes the scenario laid out in the test method. Here’s the code:
| iloveyouboss/4/test/iloveyouboss/ScoreCollectionTest.java | |
| Line 1 | package iloveyouboss; |
| - | |
| - | import static org.junit.Assert.*; |
| - | import static ... |
Read now
Unlock full access