Junit4
[ Junit4 ] allOf, anyOf
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")
)
);
}
}