반응형
Mocking Framworks
- mockito
- easymock
- jmockit
Mockito in spring boot
mockito framwork is builtin spring boot
dependency -> spring-boot-starter-test
Mockito Test Process
- setup
set expectations with mock reponses - execute
call the method want to test - assert
check the result and verify that it is expected result - verify
optionally.. verify calls (how many times called etc..)
Mokcito Test in Spring boot process
- step 1 : create mock for the dao
@Mock private MyDao myDao;
- step 2: Inject mock into service
//only inject dependencioes annotated with @Mock or @Spy @InjectMocks private MyService myService;
- step3: set up expectations
String aResponse = "Hello"; when(doTimeWork()).thenReturn(aResponse);
- step4: call method under test and assert results
assertEquals(excpectedValue, doTimeWorkResult());
반응형
'SpringBoot' 카테고리의 다른 글
Spring boot @MockBean (0) | 2022.05.22 |
---|---|
Spring boot Mockito Example - @Mock & @InjectMocks (0) | 2022.05.22 |
Unit Test - ParameterizedTest (0) | 2022.05.21 |
Java Conditional Unit Test (0) | 2022.05.21 |
spring aop (0) | 2021.11.07 |