스프링 test case

bbbbbhyun·2024년 3월 7일
0

Success case

  • assertThat(실제 값).isEqualTo(예상 값)
    ex) assertThat(disCount).isEqualTo(1000);
import static org.assertj.core.api.Assertions.assertThat;

    @Test
    @DisplayName("Vip는 10% 적용되어야 한다")
    void vip_o(){
        //given
        Member memberA = new Member(1L, "memberA", Grade.VIP);

        //when
        int disCount = discountPolicy.disCount(memberA, 10000);

        //then
        assertThat(disCount).isEqualTo(1000);
    }
    

Exception case

  • assertThrows(실행할 로직에서 터질 exception.class, () -> 실행해야 할 로직);
    ex) assertThrows(NoSuchBeanDefinitionException.class, () -> ac.getBean("xxxxxx", MemberService.class));
import static org.junit.jupiter.api.Assertions.*;
    @Test
    @DisplayName("빈이름으로 조회 X")
    void findByBeanX() {

        assertThrows(NoSuchBeanDefinitionException.class, () -> ac.getBean("xxxxxx", MemberService.class));
    }
profile
BackEnd develope

0개의 댓글