
통합 테스트, 즉 개별 테스트를 한번에 실행을 하는데, 매번 @BeforeEach 에서 데이터를 집어 넣는 경우, PK 값이 달라진다.
이를 간단하게 해결하는 방법을 알아보자.
SET REFERENTIAL_INTEGRITY FALSE;
truncate table transaction_tb;
truncate table account_tb;
truncate table appuser_tb;
SET REFERENTIAL_INTEGRITY TRUE;
@BeforeEach 실행 시점에 sql 문이 실행된다.
Controller Test 환경에서는 아래 어노테이션들을 가져간다.
@ActiveProfiles("test")
@Sql("classpath:db/teardown.sql")
@AutoConfigureMockMvc
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
public class ...Test {
// test
}