-
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
[최종점검] 스터디 과제 제출 #2
base: develop
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.
수고하셨습니다 ~
|
||
[[Member-API]] | ||
== Member API | ||
include::api/member.adoc[] |
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.
파일 분리하는 것 좋네요 ~
|
||
class MemberControllerTest extends RestDocsSupport { | ||
private final MemberService memberService = mock(MemberService.class); | ||
private static final String MEMBER_POST_URL = "/member"; |
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.
MEMBER_BASE_URL 이라고 네이밍해도 좋을 것 같아요 ~
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.
ㅋㅋ 아 근무하면서 개발했더니..~
assertTrue(answer.isAnswerType()); | ||
assertEquals(question.getQuestionContent(), answer.getQuestion().getQuestionContent()); | ||
} |
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.
assertJ 써도 좋을 것 같아요 ~
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.
네엡!!
|
||
/** | ||
* memberJpaRepository.findByNameOrThrow에서 import jakarta.persistence.EntityNotFoundException;를 던지면, | ||
* 실제로는 org.springframework.orm.jpa.JpaObjectRetrievalFailureException가 인식되어 테스트가 실패한다... |
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.
이거 왜 그런거지 ?!
CustomException 만들어서 던지는게 더 좋은 것 같긴해!
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.
그러니까요 제말이... 대체 왜냐고 ㅜ 궁금티비
.name("euna") | ||
.realAge(24) | ||
.build(); | ||
BDDMockito.given(memberJpaRepository.findByNameOrThrow(any(String.class))).willReturn(savedMember); |
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.
Service는 Mocking해서 단위 Test로 작성했네요!
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
|
||
@SpringBootTest |
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.
Mocking 할 때는 @SpringBootTest
말고 @ExtendWith(MockitoExtension.class)
만 사용해도 좋을 것 같아요!
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.
저도 @ExtendWith(MockitoExtension.class)
사용하는 거 좋아하는데 확실히 많이 가볍더라구요! 추천드립니다 ㅎㅎ
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.
헙스 좋은 지적 감사합니다!!!
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.
고생하셨습니다~ 완전 꼼꼼히 해주셨네요..! 굿굿
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("회원 나이") | ||
) |
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.
오호 이런 메서드들도 있군요.. (저번에 했었나..?)
알아갑니다 ㅎㅎ
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.
ㅋㅋㅋㅋㅋㅋ했었음!!!
@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(); | ||
} |
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.
반복되는 패턴을 이렇게 추상 클래스로 만든 부분 좋네요!
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.
굿!
answerJpaRepository.deleteAllInBatch(); | ||
questionJpaRepository.deleteAllInBatch(); |
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.
그냥 deleteAll()
이 아니라 deleteAllInBatch()
쓴 부분 좋네요 ㅎㅎ
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
|
||
@SpringBootTest |
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.
저도 @ExtendWith(MockitoExtension.class)
사용하는 거 좋아하는데 확실히 많이 가볍더라구요! 추천드립니다 ㅎㅎ
Test과제 Rule
조건 : Test 최소 20개 이상
기한
목표