March 2015
Intermediate to advanced
236 pages
5h 26m
English
When we wrote tests for the first iloveyouboss example, we visually organized our tests into three chunks: arrange, act, and assert, also known as triple-A (AAA).
| | @Test |
| | public void answersArithmeticMeanOfTwoNumbers() { |
| | ScoreCollection collection = new ScoreCollection(); |
| | collection.add(() -> 5); |
| | collection.add(() -> 7); |
| | |
| | int actualResult = collection.arithmeticMean(); |
| | |
| | assertThat(actualResult, equalTo(6)); |
| | } |
Back then, we added comments to identify each of the chunks explicitly, but these comments add no value once you understand the AAA idiom.
AAA is a part of just about every test you’ll write. With AAA, you:
Arrange. Before we execute the code we’re trying to test, ensure that the system ...
Read now
Unlock full access