ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • AssertAll
    자바/Test Code 2022. 9. 6. 18:10
    728x90
    /*
       @FunctionalInterface
       @API(status = STABLE, since = "5.0")
       public interface Executable {
    void execute() throws Throwable;
       }
    
       public static void assertAll(Executable... executables) throws MultipleFailuresError {
       AssertAll.assertAll(executables);
    }
        function interface를 활용하는 Executable를 이용하기 때문에 간단하게 람다식을 사용하여 여러개의 테스트를 한번에 검증할 수 있다. 
        */
       @Test
       public void AllAssert(){
       //given
           Human human1 = new Human("박태환",15L);
           Human human2 = new Human("박명수",15L);
           List<Human> humanList = new ArrayList<>();
       //when
           humanList.add(human1);
           humanList.add(human2);
           Stream<Human> stream = humanList.stream();
       //then
           Assertions.assertAll(
                   ()->  Assertions.assertEquals(humanList.get(0).getAge(), 15L),
                   ()-> Assertions.assertEquals(humanList.get(1).getAge(), 15L)
           );
       }
    728x90

    '자바 > Test Code' 카테고리의 다른 글

    MockMvc 테스트하기  (0) 2022.09.06
Designed by Tistory.