Search⌘ K

Another Small Increment

Explore how to incrementally develop unit tests in Java with JUnit by applying test-driven development principles. Learn to write focused tests that handle specific scenarios, use existing class methods effectively, and refactor code to pass tests progressively.

We'll cover the following...

The test demonstrates that matches returns false when the Profile instance contains no matching Answer object:

C++
public class ProfileTest {
private Answer answerThereIsNotRelocation;
// ...
@Before
public void createQuestionAndAnswer() {
questionIsThereRelocation =
new BooleanQuestion(1, "Relocation package?");
answerThereIsRelocation =
new Answer(questionIsThereRelocation, Bool.TRUE);
answerThereIsNotRelocation =
new Answer(questionIsThereRelocation, Bool.FALSE);
}
// ...
@Test
public void doesNotMatchWhenNoMatchingAnswer() {
profile.add(answerThereIsNotRelocation);
Criterion criterion =
new Criterion(answerThereIsRelocation, Weight.Important);
boolean result = profile.matches(criterion);
assertFalse(result);
}
}

Passing test

To get the test to pass, the ...