<자바와 JUnit을 활용한 실용주의 단위 테스트> 책과 Junit 5, AssertJ 공식문서를 참고하였습니다.
Right-BICEP
경계조건의 CORRECT
Conformance(준수): 값이 기대한 양식을 준수하고 있는가?
public int compareTo(Integer anotherInteger)
public List<Profile> ranked() {
Collections.sort(profiles,
(p1, p2) -> ((Integer)p1.score()).compareTo(p2.score()));
return profiles;
}
public List<Profile> ranked() {
Collections.sort(profiles,
(p1, p2) -> ((Integer)p2.score()).compareTo(p1.score()));
return profiles;
}
Specified by:
compareTo in interface Comparable<Integer>
Parameters:
| Parameter | Description |
|---|---|
| anotherInteger | 비교 대상 객체 |
Returns:
| Integer | Description |
|---|---|
| 0 | this.Integer == anotherInteger |
| 음수 | this.Integer < anotherInteger |
| 양수 | this.Integer > anotherInteger |
Range(범위): 이성적인 최솟값과 최댓값 안에 있는가?
🔥 불변식은 @After 메서드의 단언 형태로 검사 가능하다.
public class RectangleTest {
private Rectangle rectangle;
@After
public void ensureInvariant() {
assertThat(rectangle, constrainsSidesTo(100));
}
@Test
public void answersArea() {
rectangle = new Rectangle(new Point(5, 5), new Point (15, 10));
assertThat(rectangle.area(), equalTo(50));
}
@Disable
@Test
public void allowsDynamicallyChangingSize() {
rectangle = new Rectangle(new Point(5, 5));
rectangle.setOppositeCorner(new Point(130, 130));
assertThat(rectangle.area(), equalTo(15625));
}
}
overrideCardinality(기수, 집합의 원소 개수): 정확히 충분한 값들이 있는가?
🔥 0-1-n 법칙: 테스트 코드는 0, 1, n 이라는 경계 조건에만 집중