Ich kann das Host-Betriebssystem einfach mit System.getProperty("os.name") abrufen
Ich kann in meinen Tests Schutzblöcke schreiben:
Code: Select all
@Test public void testSomeWindowsAPICall() throws Exception {
if (isWindows()) {
// do tests...
}
}
Alternativ habe ich eine JUnit-Regel erstellt, die die Testmethode nur unter Windows ausführt:
Code: Select all
public class WindowsOnlyRule implements TestRule {
@Override
public Statement apply(final Statement base, final Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (isWindows()) {
base.evaluate();
}
}
};
}
private boolean isWindows() {
return System.getProperty("os.name").startsWith("Windows");
}
}
Code: Select all
@Rule public WindowsOnlyRule runTestOnlyOnWindows = new WindowsOnlyRule();
Hat jemand einen alternativen Vorschlag?
Mobile version