*assertEquals*→ 동등한지 비교해 주는 연산자 (참조 자료형끼리 비교할 경우네는 e,h를 오버라이딩 해야함)
@Test
public void testAssertEquals(){
// given 필기. 테스트를 하기 위한 준비물
int firstNum = 10;
int secondNum = 20;
int expected = 31;
// when 필기. given을 대상에 적용
Calculator calculator = new Calculator();
calculator.plusTwoNumbers(firstNum, secondNum);
int actual = calculator.plusTwoNumbers(firstNum, secondNum); // 필기. 실제 대상의 값 확인
// then 필기. 그 결과를 판단
// Assertions.assertEquals(expected, actual);
Assertions.assertEquals(expected, actual, 1); // 필기. 1만큼의 오차는 허용
Assertions.assertEquals(expected, actual, "이건 정확해야 해"); // 필기. 테스트 실패 메세지
}


assertNotEquals@Test
@DisplayName("인스턴스 동일성 비교 테스트")
void testAssetNotEqualsWithInstances(){
// given
Object obj1 = new Object();
// when
Object obj2 = new Object();
// then
Assertions.assertNotEquals(obj1, obj2);
/* 설명. Object는 e, g가 동일 비교로 작성되어 있다. */
}
assertNull@Test
@DisplayName("Null인지 테스트")
void testAssetNull(){
String str;
str = null;
Assertions.assertNull(str);
}
assertNotNull@Test
@DisplayName("Null이 아닌지 테스트")
void testAssetNotNull(){
String str;
str = "java";
Assertions.assertNotNull(str);
}
assertAll @Test
@DisplayName("하나의 테스트 케이스에 대해 여러 검증을 한번에 수행하는 경우 테스트")
void testAssertAll(){
// given
String firstName = "길동";
String lastName = "홍";
// when
Person person = new Person(firstName, lastName);
// then
Assertions.assertAll(
"그룹화된 테스트의 이름(테스트 실패시 보여짐)",
() -> Assertions.assertEquals(firstName + "1", person.getFirstName(),
() -> "firstName이 잘못됨"),
() -> Assertions.assertEquals(lastName, person.getLastName(),
() -> "LastName이 잘못됨")
);
}
assertThrows