WEBBOOK CHAPTER

Spring Boot 4.1, 시작부터 런칭까지: 34장. Testcontainers로 production 차이를 줄인다

34장. Testcontainers로 production 차이를 줄인다

통합 테스트는 PostgreSQL container를 시작하고 production과 같은 Flyway migration을 적용한다. 고정 최신 tag가 아니라 검증한 major/minor image를 잠그고 CI architecture에서도 실행한다. test마다 schema를 초기화하거나 transaction rollback을 쓰되 background thread와 outbox처럼 test transaction 밖에서 동작하는 부분을 숨기지 않는다.

repository test는 constraint와 SQL, application test는 HTTP→security→transaction→DB 전체를 검증한다. OAuth에는 test decoder를 무조건 허용하기보다 실제 claim validation을 수행하는 fixture key와 issuer를 쓴다. 시계와 UUID는 주입해 재현성을 높인다.

CI 실패 시 container log, migration version, application log, query plan을 artifact로 보존한다. 무작정 재실행해 flaky test를 통과시키지 않는다. 동시에 마지막 HIGH 항목을 확인하는 test를 여러 번 실행해 winner 1명, audit 1건, 오류 계약을 검증한다.