Skip to content

[FIX]: 테스트 환경 설정 및 의존성 주입 오류로 인한 빌드 실패 수정#99

Merged
zerochani merged 2 commits intodevelopfrom
dev2
Feb 5, 2026
Merged

[FIX]: 테스트 환경 설정 및 의존성 주입 오류로 인한 빌드 실패 수정#99
zerochani merged 2 commits intodevelopfrom
dev2

Conversation

@zerochani
Copy link
Contributor

@zerochani zerochani commented Feb 5, 2026

💡 작업 개요

  • 빌드 실패의 원인이었던 테스트 환경 설정 누락과 HealthControllerTest의 의존성 및 권한 문제를 해결하여 빌드(gradlew build)가 정상적으로 수행되도록 수정했습니다.

✅ 작업 내용

  • 기능 개발
  • 버그 수정
  • 리팩토링
  • 주석/포맷 정리
  • 기타 설정

🧪 테스트 내용

  • ./gradlew build 명령어를 실행하여 컴파일 및 전제 테스트가 통과하고 빌드가 성공함을 확인했습니다.

📝 기타 참고 사항

  • 협업 관련 이슈, 주의 사항 등

Summary by CodeRabbit

릴리스 노트

  • Tests

    • 보안 관련 테스트 인프라를 강화하여 인증/권한 흐름을 시뮬레이션하고 상태 확인 테스트의 신뢰성을 향상시켰습니다.
  • Chores

    • 테스트 환경 설정을 확장하고(테스트 구성 항목 및 비밀값 추가) Spring Security 테스트 지원을 도입해 보안 관련 테스트 작성을 용이하게 했습니다.

@zerochani zerochani self-assigned this Feb 5, 2026
@zerochani zerochani added the fix label Feb 5, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2026

📝 Walkthrough

Walkthrough

HealthControllerTest에 Spring Security 테스트 지원과 모의 보안 빈이 추가되고, 테스트용 application.yml에 서버 프로필과 jwt.secret이 추가되었으며, 빌드에 spring-security-test 의존성이 추가되었습니다.

Changes

Cohort / File(s) 요약
테스트 보안 설정
src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java
@AutoConfigureMockMvc 추가, @MockBean으로 JwtAuthenticationFilter, CustomAuthenticationEntryPoint, CustomAccessDeniedHandler 도입, @BeforeEach에서 필터의 doFilter를 체인으로 전달하도록 스텁 처리, @WithMockUser로 테스트 사용자 지정 및 관련 import 추가
테스트 환경 구성
src/test/resources/application.yml
server.profile: testjwt.secret: <long-test-value> 항목 추가
빌드 의존성
build.gradle
테스트 의존성으로 testImplementation 'org.springframework.security:spring-security-test' 추가

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

토끼의 시

🐰 작은 모의(Mock) 하나,
필터를 살짝 비껴두고,
시크릿은 테스트 품에 안겨,
헬스 체크는 평온히 뛰네,
토끼는 기뻐 폴짝폴짝. 🥕✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed PR 제목이 주요 변경사항을 명확하게 요약하고 있습니다. 빌드 실패 원인(테스트 환경 설정 누락 및 의존성 주입 오류)를 구체적으로 나타내고 있습니다.
Description check ✅ Passed PR 설명이 요구되는 템플릿 구조를 충실히 따르고 있으며, 작업 개요, 작업 내용, 테스트 내용이 완전히 작성되어 있습니다.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev2

Comment @coderabbitai help to get the list of available commands and usage tips.

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: 1

🤖 Fix all issues with AI agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java`:
- Line 27: HealthControllerTest currently disables the security filter chain via
`@AutoConfigureMockMvc`(addFilters = false) which creates a coverage gap; add one
or more tests that exercise security behavior by either removing
addFilters=false for a new test class or adding complementary tests that enable
filters and assert authentication/authorization flows (e.g., using `@WithMockUser`
on test methods) to validate HealthController endpoints under security; target
the test class/methods named HealthControllerTest and any specific test methods
calling MockMvc.perform(...) so they verify expected HTTP status/response when
unauthenticated vs authenticated and when roles/authorities are present.

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: 2

🤖 Fix all issues with AI agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java`:
- Around line 53-63: 현재 setUp()에서 jwtAuthenticationFilter.doFilter(...)를 완전히 스텁해
보안 필터를 우회하므로 인증/인가 동작이 검증되지 않습니다; 이를 해결하려면 기존 HealthControllerTest의 setUp()에서
jwtAuthenticationFilter 스텁을 제거하거나, 인증 동작을 검증할 별도 테스트 클래스를 만들어
`@AutoConfigureMockMvc`(addFilters = true) 또는 실제 필터가 적용된 MockMvc로 테스트하여 "인증되지 않은
요청은 401" 및 "권한 없는 요청은 403" 시나리오를 검사하세요; 구체적으로 JwtAuthenticationFilter을 실제로 적용하는
테스트(예: healthCheckWithoutAuth_shouldReturn401,
healthCheckWithoutRole_shouldReturn403)를 추가하고 해당 테스트에서는 setUp의 doAnswer 스텁을 사용하지
않거나 별도 클래스로 분리해 필터가 실행되도록 하세요.
- Line 13: Replace usages of the deprecated `@MockBean` in HealthControllerTest
with the new `@MockitoBean`: update the import from
org.springframework.boot.test.mock.mockito.MockBean to
org.springframework.test.context.bean.override.mockito.MockitoBean and change
any `@MockBean` annotations on fields or parameters inside the
HealthControllerTest class to `@MockitoBean` so tests use the new annotation for
Spring Boot 3.4.1 compatibility.

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.mock.mockito.MockBean;
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🌐 Web query:

Spring Boot 3.4 MockBean deprecation @MockitoBean replacement

💡 Result:

In Spring Boot 3.4, Boot’s Mockito test annotations are deprecated:

  • org.springframework.boot.test.mock.mockito.@MockBeanuse Spring Framework’s org.springframework.test.context.bean.override.mockito.@MockitoBean (github.com)
  • org.springframework.boot.test.mock.mockito.@SpyBeanuse org.springframework.test.context.bean.override.mockito.@MockitoSpyBean (github.com)

Common replacement (field-level)

// before (deprecated in Boot 3.4)
import org.springframework.boot.test.mock.mockito.MockBean;

// after
import org.springframework.test.context.bean.override.mockito.MockitoBean;

`@MockitoBean`
UserService userService;

@MockitoBean overrides (replaces, or creates if missing) a bean in the test ApplicationContext; use @Qualifier or the field name to disambiguate, or set name/value. (docs.spring.io)

If you previously used @MockBeans

There’s no need for a Boot-specific container; with Spring you can use repeatable @MockitoBean at the type level (and/or multiple fields). (docs.spring.io)

Citations:


🏁 Script executed:

find . -name "build.gradle*" -o -name "pom.xml" | head -5

Repository: Eatsfine/BE

Length of output: 69


🏁 Script executed:

cat build.gradle | grep -A 5 -B 5 "spring.boot"

Repository: Eatsfine/BE

Length of output: 1904


🏁 Script executed:

cat src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java | head -20

Repository: Eatsfine/BE

Length of output: 1081


🏁 Script executed:

cat build.gradle | grep -i "spring.boot\|gradle"

Repository: Eatsfine/BE

Length of output: 657


🏁 Script executed:

head -50 build.gradle | grep -E "plugins|springframework.boot|id"

Repository: Eatsfine/BE

Length of output: 637


@MockBean 어노테이션을 새로운 @MockitoBean으로 변경해주세요.

현재 프로젝트는 Spring Boot 3.4.1을 사용하고 있으며, 이 버전부터 org.springframework.boot.test.mock.mockito.MockBean은 deprecated 예정입니다. 새로운 @MockitoBean 어노테이션(org.springframework.test.context.bean.override.mockito.MockitoBean)으로 변경하여 향후 호환성을 유지해주세요.

🤖 Prompt for AI Agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java` at
line 13, Replace usages of the deprecated `@MockBean` in HealthControllerTest with
the new `@MockitoBean`: update the import from
org.springframework.boot.test.mock.mockito.MockBean to
org.springframework.test.context.bean.override.mockito.MockitoBean and change
any `@MockBean` annotations on fields or parameters inside the
HealthControllerTest class to `@MockitoBean` so tests use the new annotation for
Spring Boot 3.4.1 compatibility.

Comment on lines +53 to +63
@BeforeEach
void setUp() throws ServletException, IOException {
doAnswer(invocation -> {
HttpServletRequest request = invocation.getArgument(0);
HttpServletResponse response = invocation.getArgument(1);
FilterChain chain = invocation.getArgument(2);
chain.doFilter(request, response);
return null;
}).when(jwtAuthenticationFilter).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class),
any(FilterChain.class));
}
Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick | 🔵 Trivial

보안 필터 우회 방식에 대한 고려사항.

doFilter 스텁을 통해 JWT 필터를 완전히 우회하는 방식은 컨트롤러 로직 테스트에는 적합하지만, 실제 보안 동작은 검증하지 않습니다. @WithMockUser와 함께 사용해도 인증/인가 플로우 자체는 테스트되지 않습니다.

가능하다면 별도의 테스트 케이스를 추가하여 다음 시나리오를 검증하는 것을 권장합니다:

  • 인증되지 않은 요청 시 401 응답
  • 권한 없는 요청 시 403 응답
🧪 보안 동작 검증 테스트 예시
`@Test`
`@DisplayName`("인증되지 않은 요청은 401 응답을 반환한다")
void healthCheckWithoutAuth_shouldReturn401() throws Exception {
    // JwtAuthenticationFilter가 실제로 동작하도록 setUp의 doAnswer를 제거하거나
    // 별도 테스트 클래스에서 `@AutoConfigureMockMvc`(addFilters = true)로 테스트
    mockMvc
            .perform(get("/api/v1/deploy/health-check"))
            .andExpect(status().isUnauthorized());
}
🤖 Prompt for AI Agents
In `@src/test/java/com/eatsfine/eatsfine/controller/HealthControllerTest.java`
around lines 53 - 63, 현재 setUp()에서 jwtAuthenticationFilter.doFilter(...)를 완전히
스텁해 보안 필터를 우회하므로 인증/인가 동작이 검증되지 않습니다; 이를 해결하려면 기존 HealthControllerTest의
setUp()에서 jwtAuthenticationFilter 스텁을 제거하거나, 인증 동작을 검증할 별도 테스트 클래스를 만들어
`@AutoConfigureMockMvc`(addFilters = true) 또는 실제 필터가 적용된 MockMvc로 테스트하여 "인증되지 않은
요청은 401" 및 "권한 없는 요청은 403" 시나리오를 검사하세요; 구체적으로 JwtAuthenticationFilter을 실제로 적용하는
테스트(예: healthCheckWithoutAuth_shouldReturn401,
healthCheckWithoutRole_shouldReturn403)를 추가하고 해당 테스트에서는 setUp의 doAnswer 스텁을 사용하지
않거나 별도 클래스로 분리해 필터가 실행되도록 하세요.

@zerochani zerochani merged commit c1e7030 into develop Feb 5, 2026
2 checks passed
@zerochani zerochani deleted the dev2 branch February 6, 2026 04:45
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.

4 participants