Skip to content

Conversation

@leegwichan
Copy link
Member

@leegwichan leegwichan commented Aug 5, 2025

✨ 개요

  • AS-IS : StoryController가 MockService를 이용하여 테스트
  • TO-BE : StoryController가 실 서비스 객체, 실 레포지토리 객체를 이용하여 테스트하도록 수정

🧾 관련 이슈

🔍 참고 사항 (선택)

Summary by CodeRabbit

  • 테스트
    • Story 관련 테스트에서 모킹 대신 실제 데이터 생성 및 저장 방식을 사용하도록 변경되었습니다.
    • Story 엔티티 생성을 위한 StoryGenerator 유틸리티가 추가되었습니다.
    • StoryController 테스트가 서비스 레이어 모킹 없이 통합 테스트 스타일로 리팩터링되었습니다.

@coderabbitai
Copy link

coderabbitai bot commented Aug 5, 2025

Walkthrough

테스트 코드에서 기존에 StoryService를 목(mock)으로 사용하던 방식을 제거하고, 실제 StoryRepository와 ArticleRepository, 그리고 StoryGenerator 픽스처를 주입받아 사용하는 방식으로 변경되었습니다. 이에 따라 StoryControllerTest는 Mockito를 이용한 서비스 계층 스텁(stub) 방식 대신 실제 도메인 객체를 생성하여 통합 테스트 스타일로 검증하도록 리팩터링되었습니다. StoryGenerator 클래스가 신규로 추가되어 테스트용 Story 엔티티 생성을 담당합니다.

Changes

Cohort / File(s) Change Summary
BaseControllerTest 리팩터링
src/test/java/eatda/controller/BaseControllerTest.java
StoryService 목 필드 제거, StoryGenerator/ArticleRepository/StoryRepository를 Autowired로 추가 및 import 정리
StoryControllerTest 통합 테스트화
src/test/java/eatda/controller/story/StoryControllerTest.java
Mockito 스텁 제거, 실제 도메인 객체 생성 및 StoryGenerator 활용, 통합 테스트 방식으로 검증 로직 전환
StoryGenerator 픽스처 추가
src/test/java/eatda/fixture/StoryGenerator.java
Story 엔티티를 생성/저장하는 StoryGenerator 컴포넌트 신규 추가, 다양한 파라미터로 Story 생성 지원

Sequence Diagram(s)

sequenceDiagram
    participant Test as StoryControllerTest
    participant Generator as StoryGenerator
    participant Repo as StoryRepository
    participant Controller as StoryController

    Test->>Generator: Story 생성 요청(generate)
    Generator->>Repo: Story 저장(save)
    Repo-->>Generator: 저장된 Story 반환
    Test->>Controller: API 요청 (예: POST /stories)
    Controller->>Repo: Story 조회/저장 등
    Repo-->>Controller: 결과 반환
    Controller-->>Test: API 응답 반환
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

  • [Feat] 스토리 상세 조회 기능 구현 #87: Story 상세 조회 및 리스트 기능 테스트에서 실제 도메인 엔티티와 서비스 계층을 활용하는 부분이 본 PR의 통합 테스트 방식 전환과 밀접하게 연관됨.
  • [Feat] 스토리 목록 조회 구현 #84: Story 리스트 조회 기능 도입 및 테스트에서 StoryGenerator와 실제 repository 사용으로의 전환과 직접적으로 관련됨.
  • [Feat] 스토리 등록 구현 #80: Story 도메인, 서비스, 컨트롤러, DTO, repository 등 초기 구현 및 테스트에서 StoryService 목 사용이 도입된 부분과 본 PR의 리팩터링이 연결됨.

Suggested labels

test

Poem

🐇
테스트 숲에 바람이 분다,
목(Mock) 토끼는 집으로 간다.
픽스처 친구들 모여 앉아
진짜 이야기(Story) 꽃을 피운다.
저장소와 생성기로 힘을 합쳐
통합의 잔치를 벌이네!
🥕✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c168cd0 and 506103b.

📒 Files selected for processing (3)
  • src/test/java/eatda/controller/BaseControllerTest.java (3 hunks)
  • src/test/java/eatda/controller/story/StoryControllerTest.java (6 hunks)
  • src/test/java/eatda/fixture/StoryGenerator.java (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: leegwichan
PR: YAPP-Github/26th-Web-Team-1-BE#60
File: src/test/java/eatda/controller/store/StoreControllerTest.java:10-32
Timestamp: 2025-07-09T07:56:50.612Z
Learning: 컨트롤러 테스트에서 MockitoBean으로 의존성을 모킹한 경우, 상세한 비즈니스 로직 검증보다는 컨트롤러 계층의 동작(라우팅, 파라미터 처리, 응답 구조 등)을 검증하는 것이 더 적절합니다. 모킹된 데이터에 대한 상세 검증은 의미가 없기 때문입니다.
Learnt from: leegwichan
PR: YAPP-Github/26th-Web-Team-1-BE#35
File: src/test/java/timeeat/controller/auth/AuthControllerTest.java:34-35
Timestamp: 2025-06-28T02:05:30.459Z
Learning: OAuth 클라이언트를 mocking하는 테스트에서는 실제 OAuth 파라미터들을 상세히 검증하는 것보다 리다이렉트 기능 자체가 동작하는지 확인하는 것이 더 적절합니다. 모킹된 값들에 대한 상세 검증은 의미가 없기 때문입니다.
📚 Learning: 컨트롤러 테스트에서 mockitobean으로 의존성을 모킹한 경우, 상세한 비즈니스 로직 검증보다는 컨트롤러 계층의 동작(라우팅, 파라미터 처리, 응답 구조 등)을 검증하는 것이 ...
Learnt from: leegwichan
PR: YAPP-Github/26th-Web-Team-1-BE#60
File: src/test/java/eatda/controller/store/StoreControllerTest.java:10-32
Timestamp: 2025-07-09T07:56:50.612Z
Learning: 컨트롤러 테스트에서 MockitoBean으로 의존성을 모킹한 경우, 상세한 비즈니스 로직 검증보다는 컨트롤러 계층의 동작(라우팅, 파라미터 처리, 응답 구조 등)을 검증하는 것이 더 적절합니다. 모킹된 데이터에 대한 상세 검증은 의미가 없기 때문입니다.

Applied to files:

  • src/test/java/eatda/controller/story/StoryControllerTest.java
  • src/test/java/eatda/controller/BaseControllerTest.java
🔇 Additional comments (12)
src/test/java/eatda/controller/BaseControllerTest.java (3)

20-20: StoryGenerator 픽스처 추가 - 좋은 변경입니다

모킹된 StoryService 대신 실제 도메인 객체를 생성하는 픽스처를 사용하는 것은 더 현실적인 테스트 환경을 제공합니다.


21-21: 실제 Repository 의존성 추가 - 통합 테스트 전략 개선

ArticleRepository와 StoryRepository를 직접 주입받아 사용하는 것은 통합 테스트의 목적에 부합합니다. 실제 데이터베이스 상호작용을 통해 더 신뢰할 수 있는 테스트를 작성할 수 있습니다.

Also applies to: 25-25


68-69: 픽스처 생성기와 Repository 의존성 주입 - 올바른 접근

StoryGenerator와 실제 Repository들을 @Autowired로 주입받아 사용하는 것은 모킹 의존성을 제거하고 실제 도메인 객체 기반 테스트로 전환하려는 PR 목표와 완벽히 일치합니다.

Also applies to: 80-84

src/test/java/eatda/fixture/StoryGenerator.java (3)

12-25: 테스트 픽스처 클래스 설계 - 잘 구조화됨

Spring Component로 등록하여 의존성 주입을 활용하고, 기본값을 상수로 정의한 것은 좋은 설계입니다. StoryRepository를 통한 영속화도 적절합니다.


27-42: 메서드 오버로딩을 통한 유연성 제공 - 좋은 접근

다양한 시나리오를 지원하는 generate 메서드들이 잘 설계되었습니다:

  • 기본값 사용
  • 생성 시간 지정
  • 주소와 설명 커스터마이징

각 메서드가 명확한 목적을 가지고 있어 테스트 작성시 편의성을 제공합니다.


44-55: Story 객체 생성 로직의 적절한 캡슐화

private create 메서드로 Story 빌더 패턴 사용을 캡슐화한 것이 좋습니다. 모든 필수 필드를 적절히 설정하고 있습니다.

src/test/java/eatda/controller/story/StoryControllerTest.java (6)

7-8: 도메인 객체 import 추가 - 통합 테스트 전환 지원

Member, Story, ErrorResponse import 추가는 실제 도메인 객체를 사용한 테스트 작성을 지원합니다. LocalDateTime import도 시간 기반 테스트 데이터 생성에 필요합니다.

Also applies to: 10-10, 13-13


26-38: 스토리 등록 테스트 개선 - 실제 API 동작 검증

모킹된 서비스 동작 대신 실제 API 엔드포인트의 동작을 검증하도록 변경된 것이 좋습니다. 실제 등록된 storyId가 0이 아님을 확인하는 것은 적절한 검증입니다.


46-62: 실제 데이터를 사용한 목록 조회 테스트 - 의미있는 검증

storyGenerator를 사용해 실제 Story 엔티티들을 생성하고, 생성 시간 순서대로 정렬되는지 검증하는 것은 매우 의미있는 테스트입니다. 이전의 모킹된 데이터 검증보다 훨씬 현실적이고 신뢰할 수 있습니다.


71-91: 실제 도메인 객체를 사용한 상세 조회 테스트 - 품질 향상

memberGenerator와 storyGenerator를 사용해 실제 연관된 도메인 객체들을 생성하고, 이들의 속성을 검증하는 것은 훨씬 신뢰할 수 있는 테스트입니다. 실제 데이터베이스 상호작용을 통한 검증이 이루어집니다.


98-108: 실제 예외 처리 검증 - 통합 테스트의 장점

존재하지 않는 ID로 실제 API를 호출하여 404 응답과 ErrorResponse를 검증하는 것은 모킹된 예외보다 훨씬 현실적인 테스트입니다. 실제 에러 처리 로직이 정상 작동하는지 확인할 수 있습니다.


117-138: 페이징 테스트의 실제 데이터 활용 - 검증 품질 향상

실제 Member와 Story 엔티티들을 생성하여 카카오 ID별 페이징 조회를 테스트하는 것은 매우 좋은 접근입니다. 시간 순서, 멤버 정보, 스토리 ID 등 모든 응답 필드를 실제 데이터와 비교 검증할 수 있습니다.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch test/service-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Aug 5, 2025

Copy link
Member

@lvalentine6 lvalentine6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이번 PR도 고생하셨습니다! 🦖
테스트가 더 견고해졌군요

@leegwichan leegwichan merged commit e8641a3 into develop Aug 5, 2025
7 checks passed
@leegwichan leegwichan deleted the test/service-test branch August 5, 2025 13:35
@github-actions
Copy link

github-actions bot commented Aug 5, 2025

🎉 This PR is included in version 1.4.0-develop.48 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@github-actions
Copy link

🎉 This PR is included in version 1.7.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants