개요
org.junit.jupiter.api.Assumptions.* 을 사용하여 조건에 따라 테스트를 해보자.
조건에 따라 테스트 실행하기
class StudyTest {
@Test
public void create_new_study() throws Exception {
// 해당 환경 변수의 값을 가져온다.
String test_env = System.getenv("TEST_ENV");
System.out.println(test_env);
// 환경 변수의 값이 LOCAL 일 경우 아래 테스트 진행
Assumptions.assumeTrue("LOCAL".equalsIgnoreCase(test_env));
Study study = new Study(10);
assertNotNull(study);
}
@Test
@EnabledIfEnvironmentVariable(named = "TEST_ENV", matches = "LOCAL")
public void create_new_study() throws Exception {
Study study = new Study(10);
assertNotNull(study);
}
@Test
public void create_new_study() throws Exception {
Assumptions.assumingThat("LOCAL".equalsIgnoreCase(test_env), () -> {
System.out.println("LOCAL");
Study study = new Study(10)
assertNotNull(study);
});
Assumptions.assumingThat("DEV".equalsIgnoreCase(test_env), () -> {
System.out.println("DEV");
Study study = new Study(10);
assertNotNull(study);
});
}
@Test
// @EnabledOnOs({OS.MAC, OS.WINDOWS})
// @EnabledOnJre({JRE.JAVA_9, JRE.JAVA_10})
public void create_new_study() throws Exception {
Study study = new Study(10);
assertNotNull(study);
}
}
- assumeTrue(조건)
- assumingThat(조건, 테스트)
- @EnabledIfEnvironmentVariable(named = "TEST_ENV", matches = "LOCAL")
- 환경 변수에 값에 따라서 테스트를 실행할 수 있다.
- @EnabledOnOs({OS.MAC, OS.WINDOWS})
- @EnabledOnJre({JRE.JAVA_9, JRE.JAVA_10})
- 자바 버전에 따라서 테스트를 실행할 수 있다.