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

[최종점검] 스터디 과제 제출 #2

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open

Conversation

sung-silver
Copy link
Member

@sung-silver sung-silver commented Mar 27, 2024

Test과제 Rule

조건 : Test 최소 20개 이상

  • 리팩토링 가능 (Testability를 높일 수 있게 )
    • API request, response는 변경하면 됨. (요청, 응답이 바뀌면 서비스에 장애가옵니다 ...벌금 1000원 )
  • 대신에 기능 삭제는 하지마라 ㅋㅋ.
  • 각자 레포 만들어서 클론하고, 브랜치 따서 PR올리기

기한

  • 다음주 스터디에는 중간 점검을 할 거니까 한번 push만 해주세요
  • 3월 28일 22:55분까지 PR 완료 -> PR 없을시에 30000원, Test 20개에서 차감해서 한 개당 5000원
  • 4월 4일까지는 리뷰 -> 리뷰 각자 3개이상 안남기면 리뷰당 5000원

목표

  • Coverage 90% (DTO같이 불필요한 테스트는 안해도됨)
  • restdoc
  • jacoco 연동

@sung-silver sung-silver requested a review from a team March 27, 2024 06:22
@sung-silver sung-silver self-assigned this Mar 27, 2024
Copy link
Member

@unanchoi unanchoi left a comment

Choose a reason for hiding this comment

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

수고하셨습니다 ~


[[Member-API]]
== Member API
include::api/member.adoc[]
Copy link
Member

Choose a reason for hiding this comment

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

파일 분리하는 것 좋네요 ~


class MemberControllerTest extends RestDocsSupport {
private final MemberService memberService = mock(MemberService.class);
private static final String MEMBER_POST_URL = "/member";
Copy link
Member

Choose a reason for hiding this comment

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

MEMBER_BASE_URL 이라고 네이밍해도 좋을 것 같아요 ~

Copy link
Member Author

Choose a reason for hiding this comment

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

ㅋㅋ 아 근무하면서 개발했더니..~

Comment on lines +40 to +42
assertTrue(answer.isAnswerType());
assertEquals(question.getQuestionContent(), answer.getQuestion().getQuestionContent());
}
Copy link
Member

Choose a reason for hiding this comment

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

assertJ 써도 좋을 것 같아요 ~

Copy link
Member Author

Choose a reason for hiding this comment

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

네엡!!


/**
* memberJpaRepository.findByNameOrThrow에서 import jakarta.persistence.EntityNotFoundException;를 던지면,
* 실제로는 org.springframework.orm.jpa.JpaObjectRetrievalFailureException가 인식되어 테스트가 실패한다...
Copy link
Member

Choose a reason for hiding this comment

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

이거 왜 그런거지 ?!
CustomException 만들어서 던지는게 더 좋은 것 같긴해!

Copy link
Member Author

Choose a reason for hiding this comment

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

그러니까요 제말이... 대체 왜냐고 ㅜ 궁금티비

.name("euna")
.realAge(24)
.build();
BDDMockito.given(memberJpaRepository.findByNameOrThrow(any(String.class))).willReturn(savedMember);
Copy link
Member

Choose a reason for hiding this comment

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

Service는 Mocking해서 단위 Test로 작성했네요!

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;

@SpringBootTest
Copy link
Member

Choose a reason for hiding this comment

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

Mocking 할 때는 @SpringBootTest 말고 @ExtendWith(MockitoExtension.class)만 사용해도 좋을 것 같아요!

Copy link

Choose a reason for hiding this comment

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

저도 @ExtendWith(MockitoExtension.class) 사용하는 거 좋아하는데 확실히 많이 가볍더라구요! 추천드립니다 ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

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

헙스 좋은 지적 감사합니다!!!

Copy link

@mikekks mikekks left a comment

Choose a reason for hiding this comment

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

고생하셨습니다~ 완전 꼼꼼히 해주셨네요..! 굿굿

Comment on lines +48 to +58
requestFields(
fieldWithPath("nickName").type(JsonFieldType.STRING).description("회원 닉네임"),
fieldWithPath("age").type(JsonFieldType.NUMBER).description("회원 나이")
),
responseFields(
fieldWithPath("code").type(JsonFieldType.NUMBER).description("응답 코드"),
fieldWithPath("message").type(JsonFieldType.STRING).description("응답 메시지"),
fieldWithPath("data.memberId").type(JsonFieldType.NUMBER).description("회원 식별자"),
fieldWithPath("data.nickName").type(JsonFieldType.STRING).description("회원 닉네임"),
fieldWithPath("data.realAge").type(JsonFieldType.NUMBER).description("회원 나이")
)
Copy link

@mikekks mikekks Mar 27, 2024

Choose a reason for hiding this comment

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

오호 이런 메서드들도 있군요.. (저번에 했었나..?)
알아갑니다 ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

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

ㅋㅋㅋㅋㅋㅋ했었음!!!

Comment on lines +13 to +26
@ExtendWith(RestDocumentationExtension.class)
public abstract class RestDocsSupport {

protected MockMvc mockMvc;
protected ObjectMapper objectMapper = new ObjectMapper();
protected static final String json = "application/json";

@BeforeEach
void setUp(RestDocumentationContextProvider provider) {
this.mockMvc = MockMvcBuilders
.standaloneSetup(initializeController())
.apply(documentationConfiguration(provider))
.build();
}
Copy link

Choose a reason for hiding this comment

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

반복되는 패턴을 이렇게 추상 클래스로 만든 부분 좋네요!

Copy link
Member Author

Choose a reason for hiding this comment

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

굿!

Comment on lines +24 to +25
answerJpaRepository.deleteAllInBatch();
questionJpaRepository.deleteAllInBatch();
Copy link

Choose a reason for hiding this comment

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

그냥 deleteAll() 이 아니라 deleteAllInBatch() 쓴 부분 좋네요 ㅎㅎ

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;

@SpringBootTest
Copy link

Choose a reason for hiding this comment

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

저도 @ExtendWith(MockitoExtension.class) 사용하는 거 좋아하는데 확실히 많이 가볍더라구요! 추천드립니다 ㅎㅎ

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