ABOUT ME

포소니는 나의 하루이자 누군가의 공감입니다. 조용히 머물러도 좋고, 가볍게 이야기를 남겨도 좋아요. 당신의 일상도, 이곳에 스며들길 바랍니다.

Today
Yesterday
Total
  • Spring boot Test with Mockito
    Tech/SpringBoot 2022. 5. 22. 11:18
    반응형

    Mocking Framworks

    1. mockito
    2. easymock
    3. jmockit

    Mockito in spring boot

        mockito framwork is builtin spring boot
        dependency -> spring-boot-starter-test
    

    Mockito Test Process

    1. setup
      set expectations with mock reponses
    2. execute
      call the method want to test
    3. assert
      check the result and verify that it is expected result
    4. verify
      optionally.. verify calls (how many times called etc..)

    Mokcito Test in Spring boot process

    1. step 1 : create mock for the dao
       @Mock
       private MyDao myDao;
    2. step 2: Inject mock into service
       //only inject dependencioes annotated with @Mock or @Spy
       @InjectMocks
       private MyService myService;
    3. step3: set up expectations
       String aResponse = "Hello";
       when(doTimeWork()).thenReturn(aResponse);
    4. step4: call method under test and assert results
       assertEquals(excpectedValue, doTimeWorkResult());
    반응형

    'Tech > 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
Designed by Tistory.