application test : mockito - mock 생성
This commit is contained in:
@@ -1,19 +1,47 @@
|
||||
package com.example.apptest.study;
|
||||
|
||||
import com.example.apptest.member.MemberService;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class StudyServiceTest {
|
||||
|
||||
@Test
|
||||
void createStudyService() {
|
||||
@DisplayName("@Mock test")
|
||||
void test_41(@Mock MemberService memberService,
|
||||
@Mock StudyRepository studyRepository) {
|
||||
StudyService studyService = new StudyService(memberService, studyRepository);
|
||||
assertNotNull(studyService);
|
||||
System.out.println("테스트 완료!");
|
||||
}
|
||||
|
||||
// @Mock MemberService memberService;
|
||||
// @Mock StudyRepository studyRepository;
|
||||
//
|
||||
// @Test
|
||||
// @DisplayName("@Mock test")
|
||||
// void test_40() {
|
||||
// StudyService studyService = new StudyService(memberService, studyRepository);
|
||||
// assertNotNull(studyService);
|
||||
// System.out.println("테스트 완료!");
|
||||
// }
|
||||
|
||||
@Test
|
||||
@DisplayName("Mockito.mock() test")
|
||||
void test_39() {
|
||||
|
||||
MemberService memberService = Mockito.mock(MemberService.class);
|
||||
StudyRepository studyRepository = Mockito.mock(StudyRepository.class);
|
||||
StudyService studyService = new StudyService(memberService, studyRepository);
|
||||
assertNotNull(studyService);
|
||||
System.out.println("테스트 완료!");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
# 테스트 이름 표기 전략 설정
|
||||
junit.jupiter.displayname.generator.default = \
|
||||
org.junit.jupiter.api.DisplayNameGenerator$ReplaceUnderscores
|
||||
#junit.jupiter.displayname.generator.default = \
|
||||
# org.junit.jupiter.api.DisplayNameGenerator$ReplaceUnderscores
|
||||
|
||||
# 테스트 인스턴스 라이프사이클 설정
|
||||
#junit.jupiter.testinstance.lifecycle.default = per_class
|
||||
|
||||
Reference in New Issue
Block a user