Test코트 작성 중 값이 같은지 비교할때 발생
Assertions.assertEquals(member, result);
< Assertions.assertEquals 사용 시 에러 메시지 >
org.opentest4j.AssertionFailedError:
Expected :hello.hellospring.domain.Member@7920ba90
Actual :null
Assertions.assertThat(member).isEqualTo(result);
< Assertions.assertThat 사용 시 에러 메시지>
org.opentest4j.AssertionFailedError:
expected: null
but was: hello.hellospring.domain.Member@48ae9b55
Expected :null
Actual :hello.hellospring.domain.Member@48ae9b55
< 원인 >
기대한값과 달랐을 경우 발생 위 경우는 null 값이 들어와 에러 발생
null 값 뿐만아니라 기대값과 다르면 발생, 전체 Test 메서드 실행 시 다른 Test코드와 충돌하여 발생 등등
ex1)
assertThat(result.size()).isEqualTo(3);
같이 사이즈로 할경우 사이즈가 2개인데 3개로 비교하면 아래처럼 AssertionFailedError 가 발생
org.opentest4j.AssertionFailedError:
expected: 3
but was: 2
Expected :3
Actual :2
ex2)
Test코드 작성시 전체 Test에서 다른 Test코드로 인해 발생하기도함
그걸 방지하기위해
< 해결 >
member값과 비교할 result값이 제대로 나오는지 확인 및 수정
Test코드 충돌로 인한경우
@AfterEach를 활용( 메서드가 끝나면 동작하는 콜백 메서드 )
하나의 Test 메서드가 끝날때마다 clear메서드를 동작시켜 충돌 방지
@AfterEach
public void afterEach() {
repository.clearStore();
}
'에러 모음' 카테고리의 다른 글
org.springframework.boot:spring-boot-gradle-plugin:3.2.4 (0) | 2024.04.10 |
---|---|
o.s.b.d.LoggingFailureAnalysisReporter (0) | 2024.04.09 |
MissingServletRequestParameterException (0) | 2024.04.08 |
does not override abstract (0) | 2024.04.05 |
ClassCastException (0) | 2024.04.02 |