-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FEAT] 3주차 테스트 코드 제출 #3
base: main
Are you sure you want to change the base?
Conversation
좋은 인사이트네요 감사합니다 ...! |
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.
고생하셨습니다!
@@ -22,7 +23,7 @@ public class MemberController { | |||
|
|||
@PostMapping | |||
public ResponseEntity<Void> createMember(@RequestBody MemberCreateRequest request) { | |||
URI location = URI.create(memberService.create(request)); |
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.
ㅋㅋㅋㅋ 아 띄어쓰기..!!
import org.springframework.beans.factory.support.BeanDefinitionRegistry; | ||
import org.springframework.stereotype.Service; | ||
|
||
public class MockAllServiceBeanFactoryPostProcessor implements BeanFactoryPostProcessor { |
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.
이거 진짜 신기하네요..
@Autowired | ||
ObjectMapper objectMapper; | ||
|
||
MediaType json = MediaType.APPLICATION_JSON; |
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.
저랑 비슷하게 TestManager 구성하셨네요 킥 저도 MediaType을 이렇게 빼는게 가독성이 좋은 것 같더라고요
@WebMvcTest(controllers = MemberController.class) | ||
public class MemberControllerTest extends ControllerTestManager { | ||
|
||
//@Autowired |
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.
주석 지우면 좋을 것 같습니다!
.age(15) | ||
.name("김성은") | ||
.sopt(sopt) | ||
.nickname("성은짱짱걸") |
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
에 대한 단점을 생각해봤는데요! 아래 내용에는 제 뇌피셜도 살짝 들어있어서 잘못된 내용은 잡아주심 감사하겠습니다.. ㅎㅎ이번 주차에 저희는 컨트롤러 단위테스트를 진행했었잖아요? 통합테스트가 아님에도 불구하고
@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