-
Notifications
You must be signed in to change notification settings - Fork 5
[Feature] - BE 테스트 개선 스프링 컨텍스트 캐싱 최적화 #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
fa2db49
e2a7b6f
e448c21
e3c4431
c11d3a5
ebc6fbf
f69c93a
eef17d5
fc0e820
e2dc298
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package kr.touroot.global; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.restassured.RestAssured; | ||
| import kr.touroot.authentication.infrastructure.JwtTokenProvider; | ||
| import kr.touroot.utils.DatabaseCleaner; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
| import org.springframework.boot.test.web.server.LocalServerPort; | ||
|
|
||
| @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) | ||
| public abstract class AbstractControllerIntegrationTest extends AbstractIntegrationTest { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 매번 불필요하게 반복되던 공통 로직이 잘 모였군요 👍
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 저도 이름 좋다고 생각합니다! 실제로 스프링에서 제공해주는 클래스에도 Abstract로 시작하는 클래스들이 많아서 어색하지 않다고 생각되어요! |
||
|
|
||
| @Autowired | ||
| protected DatabaseCleaner databaseCleaner; | ||
| @Autowired | ||
| protected ObjectMapper objectMapper; | ||
| @Autowired | ||
| protected JwtTokenProvider jwtTokenProvider; | ||
|
|
||
| @LocalServerPort | ||
| protected int port; | ||
|
|
||
| @BeforeEach | ||
| protected void baseSetUp() { | ||
| RestAssured.port = port; | ||
| databaseCleaner.executeTruncate(); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package kr.touroot.global; | ||
|
|
||
| import kr.touroot.utils.DatabaseCleaner; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
| import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | ||
|
|
||
| @SpringBootTest(webEnvironment = WebEnvironment.NONE) | ||
| public abstract class AbstractServiceIntegrationTest extends AbstractIntegrationTest { | ||
|
|
||
| @Autowired | ||
| protected DatabaseCleaner databaseCleaner; | ||
|
|
||
| @BeforeEach | ||
| protected void baseSetUp() { | ||
| databaseCleaner.executeTruncate(); | ||
| } | ||
| } |
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@MockBean으로 인해 로그인 컨트롤러와 로그인 서비스 테스트는 각각 스프링 컨텍스트를 새로 띄우네요!혹시
@MockBean들도 추상 클래스에 protected 로 재정의하여 전체 컨텍스트를 2개로 줄이는 건 어떻게 생각하실까요??다만
MemberRepository가 전체 서비스 테스트에서 mock으로 사용시 문제가 발생하는데,애초에 로그인 서비스 테스트에서
MemberRepository를 목으로 사용하지 않는 것이 더 좋지 않을까 생각되네요!There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
우선 운용하는
@MockBean은 KakaoOauthProvider 하나로 좁혀졌습니다.MemberRepository, JwtTokenProvider 등, 필요없는 MockBean은 전부 제거하였어요
그런데
@MockBean을 추상 클래스에 위치시키게 되면 MockBean이 관심사가 아닌 테스트들까지 참조가 열리게 됩니다.그리고 MockBean을 XXXIntegrationTest에 위치시키는 것 자체가 통합 테스트를 부정하는 어폐가 있다고 생각도 드네요
MockBean을 추상클래스안에 위치시키면 스프링 애플리케이션 컨텍스트를 두개로 운용할 수 있음을 확인했는데요~ 선술한 이유를 근거로 추상클래스안에 위치시키지는 않았습니다.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여담으로 통합테스트의 의미를 극한으로 살리기 위해서 MockBean stubbing이 아닌 MockServer를 운용하는 방식도 생각해보았어요. 이 경우 통합테스트의 의미를 살리면서 애플리케이션 컨텍스트도 캐싱하며 사용할 수 있는데요..! 이는 이번 PR의 관심사는 아닌 듯 하군요. 다음 이슈에서 작업되면 매우 좋을 것 같습니다.
MockServer 궁금하시면 다음 링크 한 번 살펴봐주세요
MockServer 공식 사이트