Skip to content

Conversation

@Gyuhyeok99
Copy link
Contributor

관련 이슈

작업 내용

커뮤니티 관련 통합 테스트 데이터 fixture 메서드로 변경했습니다!

드디어 BaseIntegrationTest를 다 없앴네요!

특이 사항

리뷰 요구사항 (선택)

@coderabbitai
Copy link

coderabbitai bot commented Jun 7, 2025

Walkthrough

  1. 테스트 픽스처 및 빌더 클래스 대거 추가
      - Board, Post, Comment, PostImage 엔티티 각각에 대해 테스트 픽스처와 빌더 클래스가 새롭게 도입되었습니다.
      - 각 픽스처는 Spring의 @TestComponent와 Lombok의 @RequiredArgsConstructor를 사용하여 의존성을 주입받고, 테스트 데이터 생성을 위한 메서드를 제공합니다.
      - BoardFixture, PostFixture, CommentFixture, PostImageFixture 등은 각각의 엔티티 생성을 한글 메서드명으로 추상화하여 재사용성을 높였습니다.

  2. 테스트 전용 리포지토리 인터페이스 추가
      - Board 엔티티의 테스트용 리포지토리 인터페이스가 추가되어, 게시판 코드로 게시글 리스트를 함께 조회하는 커스텀 쿼리 메서드를 제공합니다.

  3. 주요 서비스 테스트 리팩토링
      - 기존에 직접 엔티티를 생성하거나 리포지토리를 사용하던 테스트 코드들이 픽스처 기반으로 전환되었습니다.
      - CommentServiceTest, PostCommandServiceTest, PostLikeServiceTest, PostQueryServiceTest 등에서 중복된 엔티티 생성 로직이 제거되고, 픽스처를 통한 일관된 테스트 데이터 세팅으로 변경되었습니다.
      - 각 테스트 클래스의 @BaseIntegrationTest 어노테이션이 @TestContainerSpringBootTest로 교체되었습니다.

  4. 통합 테스트 베이스 클래스 삭제
      - 다양한 도메인 엔티티와 관계형 데이터를 한 번에 세팅하던 BaseIntegrationTest 추상 클래스가 완전히 삭제되었습니다.
      - 이와 함께 다수의 public static 테스트 데이터 변수와 복잡한 @BeforeEach 및 헬퍼 메서드들도 모두 제거되었습니다.

  5. 테스트 데이터 생성 및 검증 방식 간소화
      - 테스트 내에서 직접적으로 엔티티의 세부 필드를 검증하던 부분이, 픽스처를 활용한 ID 및 개수 등 주요 필드 중심 검증으로 단순화되었습니다.

Suggested reviewers

  • wibaek
  • nayonsoso

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00ea711 and 6c344f8.

📒 Files selected for processing (1)
  • src/test/java/com/example/solidconnection/community/board/fixture/BoardFixture.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/com/example/solidconnection/community/board/fixture/BoardFixture.java
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • @coderabbitai modularize this function.
  • 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.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

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

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 7

🧹 Nitpick comments (1)
src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java (1)

48-58: 2. Fixture 의존성 주입 구조 개선

Fixture들이 체계적으로 주입되어 테스트 데이터 생성을 중앙화했습니다. 하지만 더 나은 가독성을 위해 다음과 같은 정리를 제안합니다:

 @Autowired
 private SiteUserFixture siteUserFixture;
-
 @Autowired
 private BoardFixture boardFixture;
-
 @Autowired
 private PostFixture postFixture;
-
 @Autowired
 private CommentFixture commentFixture;
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ac0f60e and 00ea711.

📒 Files selected for processing (14)
  • src/test/java/com/example/solidconnection/community/board/fixture/BoardFixture.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/board/fixture/BoardFixtureBuilder.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/board/repository/BoardRepositoryForTest.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java (12 hunks)
  • src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/post/fixture/PostImageFixture.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/post/fixture/PostImageFixtureBuilder.java (1 hunks)
  • src/test/java/com/example/solidconnection/community/post/service/PostCommandServiceTest.java (13 hunks)
  • src/test/java/com/example/solidconnection/community/post/service/PostLikeServiceTest.java (7 hunks)
  • src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java (5 hunks)
  • src/test/java/com/example/solidconnection/support/integration/BaseIntegrationTest.java (0 hunks)
💤 Files with no reviewable changes (1)
  • src/test/java/com/example/solidconnection/support/integration/BaseIntegrationTest.java
🧰 Additional context used
🧬 Code Graph Analysis (8)
src/test/java/com/example/solidconnection/community/post/fixture/PostImageFixture.java (1)
src/test/java/com/example/solidconnection/community/post/fixture/PostImageFixtureBuilder.java (1)
  • TestComponent (9-33)
src/test/java/com/example/solidconnection/community/post/fixture/PostImageFixtureBuilder.java (1)
src/test/java/com/example/solidconnection/community/post/fixture/PostImageFixture.java (1)
  • TestComponent (8-20)
src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java (1)
src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java (1)
  • TestComponent (11-77)
src/test/java/com/example/solidconnection/community/board/fixture/BoardFixture.java (1)
src/test/java/com/example/solidconnection/community/board/fixture/BoardFixtureBuilder.java (1)
  • TestComponent (8-31)
src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java (1)
src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java (1)
  • TestComponent (9-35)
src/test/java/com/example/solidconnection/community/board/fixture/BoardFixtureBuilder.java (1)
src/test/java/com/example/solidconnection/community/board/fixture/BoardFixture.java (1)
  • TestComponent (10-39)
src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java (1)
src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixtureBuilder.java (1)
  • TestComponent (10-53)
src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java (1)
src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java (1)
  • TestComponent (10-35)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: build
🔇 Additional comments (23)
src/test/java/com/example/solidconnection/community/post/fixture/PostImageFixture.java (1)

1-21: 깔끔한 픽스처 패턴 구현이 인상적입니다! 👍

  1. 테스트 가독성 향상: 한글 메서드명 게시글_이미지가 테스트 의도를 명확하게 표현합니다
  2. 적절한 책임 분리: PostImageFixtureBuilder에 실제 생성 로직을 위임하고, 이 클래스는 편의 메서드만 제공하는 구조가 깔끔합니다
  3. 일관된 패턴: 다른 픽스처 클래스들과 동일한 구조를 따라 유지보수성이 좋습니다
src/test/java/com/example/solidconnection/community/board/repository/BoardRepositoryForTest.java (1)

1-15: 테스트 성능을 고려한 우수한 저장소 설계입니다! 🚀

  1. N+1 문제 방지: LEFT JOIN FETCH를 사용하여 게시판과 게시글을 한 번에 조회하는 것이 테스트 성능에 도움이 됩니다
  2. 명확한 메서드명: findByCodeWithPosts로 메서드의 의도가 분명하게 드러납니다
  3. 안전한 반환 타입: Optional을 사용하여 null 안전성을 확보했습니다
src/test/java/com/example/solidconnection/community/post/service/PostLikeServiceTest.java (2)

27-27: 테스트 어노테이션 변경이 적절합니다! ✨

BaseIntegrationTest에서 TestContainerSpringBootTest로의 전환이 픽스처 기반 테스트 구조와 잘 어울립니다.


43-62: 픽스처 기반 테스트 데이터 설정이 훌륭합니다! 🎯

  1. 중앙화된 설정: @beforeeach에서 공통 테스트 데이터를 한 번에 설정하여 코드 중복을 제거했습니다
  2. 가독성 향상: 픽스처를 통한 데이터 생성으로 테스트 의도가 명확해졌습니다
  3. 유지보수성 개선: 테스트 데이터 변경 시 한 곳만 수정하면 되는 구조입니다
src/test/java/com/example/solidconnection/community/post/fixture/PostFixture.java (1)

10-35: 테스트 픽스처 구현이 깔끔합니다!

  1. 일관된 한글 메서드명: 게시글 메서드명이 프로젝트의 네이밍 컨벤션과 일치합니다
  2. 적절한 기본값 설정: likeCount와 viewCount를 0L로 초기화하는 것이 합리적입니다
  3. 깔끔한 파사드 패턴: PostFixtureBuilder에 대한 간단하고 명확한 래퍼 역할을 잘 수행합니다
src/test/java/com/example/solidconnection/community/comment/fixture/CommentFixture.java (1)

9-35: 댓글 픽스처 구현이 잘 설계되었습니다!

  1. 명확한 메서드 분리: 부모_댓글자식_댓글로 용도에 맞게 분리된 구조가 직관적입니다
  2. 일관된 네이밍: 한글 메서드명이 프로젝트 전반의 컨벤션과 일치합니다
  3. 적절한 파라미터 구조: 자식 댓글에만 parentComment 파라미터를 추가한 설계가 논리적입니다
  4. 깔끔한 위임 패턴: CommentFixtureBuilder에 대한 명확한 위임으로 책임이 잘 분리되어 있습니다
src/test/java/com/example/solidconnection/community/comment/service/CommentServiceTest.java (4)

37-39: 1. 테스트 어노테이션 변경 승인

@BaseIntegrationTest에서 @TestContainerSpringBootTest로 변경한 것이 적절합니다. BaseIntegrationTest 클래스 제거에 따른 일관된 변경사항입니다.


63-75: 3. 테스트 데이터 초기화 로직 승인

@BeforeEach에서 공통 테스트 데이터를 설정하는 것이 좋습니다. 각 테스트에서 반복되던 데이터 생성 로직이 제거되어 테스트가 더 깔끔해졌습니다.


83-84: 4. Fixture 메서드 사용으로 개선된 가독성

한글 메서드명을 사용한 Fixture가 테스트의 의도를 명확하게 표현합니다. 부모_댓글, 자식_댓글 등의 메서드명이 직관적입니다.


99-107: 5. 단순화된 어설션 로직

기존의 복잡한 어설션에서 핵심적인 소유권 검증에 집중한 것이 좋습니다. 테스트의 목적이 더 명확해졌습니다.

src/test/java/com/example/solidconnection/community/post/service/PostCommandServiceTest.java (5)

47-49: 1. 테스트 어노테이션 변경 일관성 확인

다른 테스트 클래스들과 동일하게 @TestContainerSpringBootTest로 변경된 것이 적절합니다. 일관된 리팩토링 적용을 확인했습니다.


67-76: 2. Fixture 의존성 주입 구조

PostImageFixture 추가를 포함하여 필요한 모든 Fixture들이 체계적으로 주입되었습니다. 테스트 데이터 생성의 중앙화가 잘 이루어졌습니다.


82-101: 3. @beforeeach 설정 로직 개선

공통 테스트 데이터를 미리 생성하여 각 테스트의 보일러플레이트 코드를 줄인 것이 훌륭합니다. 특히 postquestionPost를 구분하여 생성한 것이 테스트 시나리오에 적합합니다.


177-178: 4. PostImageFixture 활용 개선

PostImageFixture를 사용하여 이미지 생성 로직이 간소화되었습니다. 테스트의 가독성과 유지보수성이 향상되었습니다.

Also applies to: 269-270


314-321: 5. Helper 메서드에서 Fixture 사용 일관성

createPostCreateRequest 메서드에서도 boardFixture.자유게시판()을 사용하여 Fixture 패턴을 일관되게 적용한 것이 좋습니다.

src/test/java/com/example/solidconnection/community/post/fixture/PostFixtureBuilder.java (3)

26-64: 2. Fluent API 메서드 구현 완성도

모든 Post 속성에 대한 setter 메서드가 체계적으로 구현되어 있습니다. 메서드 체이닝이 가능하도록 this를 반환하는 것도 적절합니다.


66-76: 3. 엔티티 생성 및 저장 로직

create() 메서드에서 Post 엔티티를 생성하고 연관관계를 설정한 후 저장하는 로직이 적절합니다. setBoardAndSiteUser 호출로 양방향 연관관계가 올바르게 설정됩니다.


13-77: 4. 전체적인 설계 패턴 일관성

PostFixtureBuilder와 CommentFixtureBuilder가 동일한 패턴을 따르고 있어 코드베이스의 일관성이 좋습니다. 다른 엔티티들도 이 패턴을 따를 것으로 예상되어 유지보수성이 향상될 것입니다.

src/test/java/com/example/solidconnection/community/post/service/PostQueryServiceTest.java (5)

4-4: 픽스처 기반 테스트로의 전환이 잘 이루어졌습니다.

BaseIntegrationTest에서 TestContainerSpringBootTest로의 변경과 함께 필요한 픽스처 클래스들이 적절히 import되었습니다. 테스트 설정이 더욱 명시적이고 이해하기 쉬워졌습니다.

Also applies to: 6-6, 11-11, 12-12, 15-15, 28-28


42-42: 테스트 데이터 관리 방식이 개선되었습니다.

  1. 리포지토리 의존성을 픽스처로 교체하여 테스트 데이터 생성 로직을 캡슐화했습니다.
  2. 공통 테스트 데이터(post1, post2, post3)를 필드로 선언하여 재사용성을 높였습니다.

이러한 변경으로 테스트 코드의 가독성과 유지보수성이 향상되었습니다.

Also applies to: 45-45, 48-48, 51-51, 53-54, 57-59


63-87: 테스트 데이터 설정이 체계적으로 개선되었습니다.

  1. 픽스처 메서드를 사용하여 테스트 데이터 생성이 명확해졌습니다.
  2. 다양한 카테고리와 게시판으로 구성된 테스트 데이터가 포괄적인 테스트 시나리오를 제공합니다.
  3. 한글 메서드명 사용으로 가독성이 크게 향상되었습니다.

테스트 데이터의 의도가 명확하게 드러나는 좋은 리팩토링입니다.


93-96: 테스트 데이터 사용이 명확해졌습니다.

이제 setUp에서 생성된 구체적인 테스트 데이터를 사용하여 테스트의 예측 가능성과 안정성이 크게 향상되었습니다. 필터링 로직도 설정된 테스트 데이터와 일치하여 의도한 대로 동작할 것입니다.

Also applies to: 116-118


140-165: 테스트 격리와 픽스처 활용이 훌륭합니다.

  1. 특정 테스트 요구사항에 맞는 별도의 테스트 데이터를 생성하여 테스트 격리를 잘 구현했습니다.
  2. 픽스처를 활용한 이미지와 댓글 생성으로 설정 코드가 깔끔해졌습니다.
  3. 어서션을 ID와 컬렉션 크기 검증에 집중하여 테스트의 핵심 목적이 명확해졌습니다.
  4. Redis 관련 검증은 그대로 유지하여 캐싱 기능 테스트의 완전성을 보장했습니다.

테스트 코드의 가독성과 유지보수성이 크게 개선된 좋은 리팩토링입니다.

Copy link
Member

@wibaek wibaek left a comment

Choose a reason for hiding this comment

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

커밋이 잘 나뉘어져서 읽기 좋네요 :)

Copy link
Collaborator

@nayonsoso nayonsoso left a comment

Choose a reason for hiding this comment

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

수고하셨습니다🥳

Comment on lines -58 to +88
List<PostFindCommentResponse> responses = commentService.findCommentsByPostId(
테스트유저_1,
testPost.getId()
);
List<PostFindCommentResponse> responses = commentService.findCommentsByPostId(user1, post.getId());
Copy link
Collaborator

Choose a reason for hiding this comment

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

"세개까지는 한줄로, 네개 부터는 싹 다 개행" 하는 컨벤션 지키니 가독성이 너무 좋아졌네요!!

@Gyuhyeok99 Gyuhyeok99 merged commit 3d5820c into solid-connection:develop Jun 18, 2025
2 checks passed
@Gyuhyeok99 Gyuhyeok99 deleted the refactor/332-community-test-fixture-module branch July 10, 2025 07:56
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.

refactor: Community 관련 통합 테스트 데이터 fixture 메서드로 변경

3 participants