Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

[FEAT] 3주차 테스트 코드 제출 #3

wants to merge 1 commit into from

Conversation

mikekks
Copy link
Contributor

@mikekks mikekks commented Mar 12, 2024

  • 3주차 테스트 코드 작성했습니다.
  • BDDMockito도 살짝 찍먹해봤습니다..ㅋㅋ

@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

@mikekks mikekks self-assigned this Mar 12, 2024
@mikekks mikekks requested review from a team and removed request for sung-silver, unanchoi and gardening-y March 12, 2024 12:42
@unanchoi
Copy link
Member

좋은 인사이트네요 감사합니다 ...!

Copy link
Member

@sung-silver sung-silver left a 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));
Copy link
Member

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 {
Copy link
Member

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;
Copy link
Member

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
Copy link
Member

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("성은짱짱걸")
Copy link
Member

Choose a reason for hiding this comment

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

감사티비 ㅋㅋ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants