Assumptions.
assumeTrue
@Test void TEST_ENV_환경변수가_LOCAL_일때만_실행(){ Assumptions.assumeTrue("LOCAL".equalsIgnoreCase(System.getenv("TEST_ENV"))); Study study = new Study(); assertThat(study).isNotNull(); }
조건이 틀렸다면 test는 ignored됨
참고) 환경변수를 바꾸면 인텔리제이를 다시 띄워야함
Assumptions.
asumingThat
@Test void testInAllEnvironments() { Assumptions.assumingThat("CI".equals(System.getenv("ENV")), () -> { // perform these assertions only on the CI server assertEquals(2, calculator.divide(4, 2)); }); // perform these assertions in all environments assertEquals(42, calculator.multiply(6, 7)); }
@EnabledOnOs,
@DisabledOnOs
@EnabledOnJre,
@DisabledOnJre
@EnabledOnIfSystemProperty,
@DisabledOnIfSystemProperty
@EnabledOnIfEnvironmentVariable,
@DisabledIfEnvironmentVariable
사용 예시 및 커스텀 Annotation -
@TestOnMac
@Test @EnabledOnOs(MAC) void onlyOnMacOs() { // ... } @TestOnMac void testOnMac() { // ... } @Test @EnabledOnOs({ LINUX, MAC }) void onLinuxOrMac() { // ... } @Test @DisabledOnOs(WINDOWS) void notOnWindows() { // ... } @Target(ElementType.METHOD) @Retention(RetentionPolicy.RUNTIME) @Test @EnabledOnOs(MAC) @interface TestOnMac { }