Skip to content

Conversation

@ljdongz
Copy link
Collaborator

@ljdongz ljdongz commented Jun 4, 2025

#️⃣ 연관된 이슈

  • close #52

📝 작업 내용

DTO CodingKey와 FirestoreFieldKey 간 매핑 일치 여부 테스트 코드를 작성하였습니다.
이 과정에서 여러 모듈의 테스트 코드에서 재사용 가능한 코드를 위해 TestSupport라는 이름의 모듈을 구현했습니다.

🎨 스크린샷

💬 추가 설명

1. 작업 의미

이 작업의 의미는 개발자의 실수로 CodingKey 케이스 값을 변경하거나, Firestore의 FieldKey 값을 변경하면서 발생할 수 있는 매핑 불일치를 대응하기 위함입니다.
다만, 테스트 코드를 실행해야만 일치 여부를 확인할 수 있다는 점, 즉 개발자가 디버깅 환경에서 빌드하는 과정에서는 일치 여부를 확인할 수 없다는 점이 완벽한 대응책은 아니라고 느껴지긴 합니다.

2. TestSupport 모듈 구현

류성두님이 뱅크샐러드 블로그 글을 참고하였습니다.
이를 참고하여 given, when, then의 메서드를 제공하는 BaseTestCase 프로토콜을 구현하였습니다.
이는 모든 테스트코드들이 각 단계별 작업을 더 명확히 나눠질 수 있도록 하면서 가독성을 높이기 위함입니다.

public protocol BaseTestCase {
  /// 초기에 주입받아야 할 데이터를 지정합니다
  func given(_ task: () -> Void)
  
  /// 발생해야 할 이벤트, 또는 메소드 호출등을 실행시킵니다
  func when(_ task: () -> Void)
  
  /// 결과 값이 기대와 같은지 확인합니다
  func then(_ task: () -> Void)
}

public extension BaseTestCase {
  func given(_ task: () -> Void) { task() }
  
  func when(_ task: () -> Void) { task() }
  
  func then(_ task: () -> Void) { task() }
}

실제 사용 예시는 아래와 같습니다.

struct AppTests: BaseTestCase {
  @Test func basicTest() async throws {
    given { // 초기에 주입받아야 할 데이터를 지정 }
    when { // 발생해야 할 이벤트, 또는 메소드 호출등을 실행 }
    then { // 결과 값이 기대와 같은지 확인 }
  }
}

@ljdongz ljdongz requested a review from f-lab-barry June 4, 2025 09:25
@ljdongz ljdongz self-assigned this Jun 4, 2025
@ljdongz ljdongz changed the base branch from develop to feature/#50 June 4, 2025 09:30
@sonarqubecloud
Copy link

sonarqubecloud bot commented Jun 6, 2025

@ljdongz ljdongz closed this Jun 6, 2025
@ljdongz ljdongz deleted the test/#52 branch June 6, 2025 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants