Conversation
Member
|
좋은 인사이트네요 감사합니다 ...! |
sung-silver
approved these changes
Mar 13, 2024
|
|
||
| @PostMapping | ||
| public ResponseEntity<Void> createMember(@RequestBody MemberCreateRequest request) { | ||
| URI location = URI.create(memberService.create(request)); |
| import org.springframework.beans.factory.support.BeanDefinitionRegistry; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| public class MockAllServiceBeanFactoryPostProcessor implements BeanFactoryPostProcessor { |
| @Autowired | ||
| ObjectMapper objectMapper; | ||
|
|
||
| MediaType json = MediaType.APPLICATION_JSON; |
Member
There was a problem hiding this comment.
저랑 비슷하게 TestManager 구성하셨네요 킥 저도 MediaType을 이렇게 빼는게 가독성이 좋은 것 같더라고요
| @WebMvcTest(controllers = MemberController.class) | ||
| public class MemberControllerTest extends ControllerTestManager { | ||
|
|
||
| //@Autowired |
| .age(15) | ||
| .name("김성은") | ||
| .sopt(sopt) | ||
| .nickname("성은짱짱걸") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@MockBean
@MockBean에 대한 단점을 생각해봤는데요! 아래 내용에는 제 뇌피셜도 살짝 들어있어서 잘못된 내용은 잡아주심 감사하겠습니다.. ㅎㅎ이번 주차에 저희는 컨트롤러 단위테스트를 진행했었잖아요? 통합테스트가 아님에도 불구하고
@MockBean이 너무 무거운? 작업이라는 느낌이 들었는데요..! 그럼에도 불구하고 너무 반복적으로 호출되지 않나? 라는 생각이 들었습니다!해당 문제인식을 갖고 검색을 좀 해보니 비슷한 맥락의 글이 몇개 있더라고요! 보통 "Application Context 초기화" 문제라고 합니다!
그래서 이번에 나름
MockAllServiceBeanFactoryPostProcessor를 사용해서 MockBean을 실제 Bean으로 등록해서 Application Context 초기화 문제를 해결해보고자 했습니다!뿐만 아니라 테스트 코드에 대한 리팩토링을 해서 테스트 코드 성능 최적화를 하기도 하더라고요??! 이 부분은 처음 들어본 부분이라 개인적으로 신선했습니다.. 이 부분도 함께 공유드립니다..ㅎ
참고링크1 : https://tech.kakaopay.com/post/mock-test-code/#testconfiguration-%EA%B8%B0%EB%B0%98%EC%9C%BC%EB%A1%9C-application-context-%EC%B4%88%EA%B8%B0%ED%99%94-%ED%95%B4%EA%B2%B0
참고링크2 : https://tecoble.techcourse.co.kr/post/2022-10-15-test-code-optimization/
참고링크3 : https://mangkyu.tistory.com/244