Java JUnit test selon plateforme

JUnit 5 Jupiter

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

class TestPlatform {

  @Test
  @EnabledOnOs({OS.LINUX, OS.MAC})
  void onLinuxAndMac() {
    System.out.println("Test pour Linux et Mac");
    assertEquals(3, 1 + 2);
  }

  @Test
  @DisabledOnOs(OS.WINDOWS)
  void notOnWindows() {
    System.out.println("Test sauf pour Windows");
    assertEquals(3, 1 + 2);
  }

}

JUnit 4 et Apache Commons Lang

import static org.junit.Assert.assertEquals;
import static org.junit.Assume.assumeTrue;

import org.apache.commons.lang3.SystemUtils;
import org.junit.Before;
import org.junit.Test;

public class TestPlatform {

  @Before
  public void setUp() {
    assumeTrue(SystemUtils.IS_OS_WINDOWS);
  }

  @Test
  public void test() {
    System.out.println("Test pour Windows");
    assertEquals(3, 1 + 2);
  }

}

Commentaires