November 2024
Intermediate to advanced
300 pages
7h 12m
English
You’ve written a zero-based test (a test for the “zero” case) and a one-based test so far. It’s time to slam out a many-based test:
| | @Test |
| | void withMultipleRatingsDividesTotalByCount() { |
| | creditHistory.add(new CreditRating(780)); |
| | creditHistory.add(new CreditRating(800)); |
| | creditHistory.add(new CreditRating(820)); |
| | |
| | var result = creditHistory.arithmeticMean(); |
| | |
| | assertEquals(800, result); |
| | } |
You can create this test by copying the one-based test, duplicating a couple of lines in order to add a total of three credit ratings, and changing the expected value for the assertion. It should pass. Break it; it should fail. Fix ...
Read now
Unlock full access