상세 컨텐츠

본문 제목

[ Junit4 ] allOf, anyOf

Junit4

by kwanghyup 2020. 6. 18. 08:42

본문

import org.junit.Test;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;

public class SampleTest {

    @Test
    public void test_allOf() {
        String actual = "public static void test";

        // allOf : 내부의 모든 매처들이 일치하는 경우 테스트 통과
        assertThat(actual, allOf(
                    containsString("ati"),
                    startsWith("pub"),
                    equalTo("public static void test")
                )
        );
    } // end

    @Test
    public void test_anyOf(){
        String actual = "public static void test";

        // allOf : 내부의 매처들 중에 적어도 하나가 일치하는 경우 테스트 통과
        assertThat(actual, anyOf(
                    equalTo("good"),
                    startsWith("public"),       //일치
                    endsWith("bad"),
                    containsString("kind")
                )
        );
    }

}

관련글 더보기

댓글 영역