March 2015
Intermediate to advanced
236 pages
5h 26m
English
After the second pass through the TDD cycle, we have code we can clean up. Not in the Profile class, but in the tests. We want the tests to stay short and clear. Both our tests instantiate Profile. Create a Profile field and move the common initialization to an @Before method:
| iloveyouboss/tdd-6/test/iloveyouboss/ProfileTest.java | |
| | public class ProfileTest { |
* | private Profile profile; |
| | |
* | @Before |
* | public void createProfile() { |
* | profile = new Profile(); |
* | } |
| | |
* | @Test |
* | public void matchesNothingWhenProfileEmpty() { |
* | Question question = new BooleanQuestion(1, "Relocation package?"); |
* | Criterion criterion = |
* | new Criterion(new Answer(question, Bool.TRUE), Weight.DontCare); |
* | |
* | boolean result = profile.matches(criterion); ... |
Read now
Unlock full access