Skip to content

백엔드 테스트 인프라 구축 및 핵심 테스트 코드 작성 #132

@Cupcakes33

Description

@Cupcakes33

배경

현재 백엔드에 contextLoads() 외 테스트 코드가 전무하며, test profile·fixture·mock 등 테스트 인프라도 없는 상태다.
서비스 ~40개·도메인 13개 패키지 규모로 성장했고, FULLTEXT native query 등 MySQL 전용 문법이 존재하여
Testcontainers MySQL 기반의 테스트 체계가 필요함.

설명

  • 테스트 인프라 기반 구축 (Testcontainers MySQL, test profile, fixture 팩토리, Security/Tenant 지원 클래스)
  • 도메인 단위 테스트 작성 (Entity 상태 전이, 비즈니스 규칙 검증)
  • 서비스 단위 테스트 작성 (Mockito 기반 핵심 비즈니스 로직 검증)
  • 컨트롤러 슬라이스 테스트 작성 (선택적, @WebMvcTest)
  • Repository 슬라이스 테스트 작성 (선택적, 커스텀 쿼리 대상)

완료 조건

1. 테스트 인프라

  • build.gradle에 Testcontainers 의존성 추가됨 (spring-boot-testcontainers, testcontainers:mysql, testcontainers:junit-jupiter)
  • application-test.yml 생성됨 (Flyway 스키마 생성, JWT 테스트 키 포함)
  • TestcontainersConfig 생성됨 (@ServiceConnection 기반 MySQL 8.0 컨테이너)
  • ServiceTest 메타 어노테이션 생성됨
  • TenantTestSupport에서 TenantContextHolder 세팅/정리 지원함
  • SecurityTestSupport에서 @CurrentUserId 주입 테스트 지원함
  • 주요 도메인별 Fixture 팩토리 생성됨 (Student, Dojang, User, Invoice 등)
  • ./gradlew test 실행 시 전체 테스트 통과함

2. 도메인 단위 테스트 (P0)

  • Invoice Entity 생성·상태 전이·비즈니스 규칙 테스트 작성됨
  • Payment Entity 생성·상태 전이 테스트 작성됨
  • Refund Entity 생성·상태 전이 테스트 작성됨
  • Attendance Entity 상태 전이 테스트 작성됨

3. 서비스 단위 테스트 (P0)

  • InvoiceService 핵심 메서드 Mockito 기반 테스트 작성됨
  • PaymentService 핵심 메서드 테스트 작성됨
  • PgPaymentService 결제 승인/보상 취소 테스트 작성됨
  • RefundService 환불 처리 테스트 작성됨
  • AutoInvoiceService 자동 청구 로직 테스트 작성됨
  • 외부 서비스(TossPaymentClient, SmsService) Mock으로 대체됨

4. 테스트 품질

  • 모든 테스트가 Given-When-Then 패턴을 따름
  • @DisplayName으로 한글 설명 작성됨
  • 테스트 간 독립성 보장됨 (순서 무관하게 통과)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions