I am playing around with Junit 5 (conditional skip) and jdk-11.01 to ignore some tests for the first time. I do not manage to get the @Disable/@Enable to disable testcases. Please share any ideas how to get this to work?
Example:
@DisabledOnOs(OS.LINUX)
@EnableOnOs(OS.WINDOWS)
@DisabledForJreRange
https://www.baeldung.com/junit-5-conditional-test-execution
The only exclusion that still works are the @Ignore flag.
I have tested to run a test suite from "GitHub Actions" or locally from IntelliJ with the Junit 5 plugin, and the tests are still executed even though the condition is met (example running a test on Linux machine) when test is marked @EnableOnOs(OS.WINDOWS)!
Example test:
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
...
@EnabledOnOs(OS.WINDOWS)
@Test
public void onlyRunOnWindowsTest() {
log.info("Test run on Windows env. only");
// more test code ...
}
Is there anything else I need to configure the test with in order to have this working?
I also have this:
from dependencis in gradle.build I have: // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: '5.7.0'
in project External Libraries (intelliJ) I have:
> Gradle:junit:junit:4.1
I tried to remove this junit 4.1 (if there were due to conflict reasons), from project but this popped up again directly from a Gradle refresh. I guess junit5 uses this jar.
> Gradle:org.junit.jupiter:junit-jupiter-api:5.7.0
testImplementation("org.junit.jupiter:junit-jupiter:5.7.0")
andtest { useJUnitPlatform() }
. If you're using JUnit 5 then you shouldn't have JUnit 4 unless you're using the former's vintage test engine. – Slaw@Ignore
. That is a JUnit 4 annotation and does not exist in JUnit 5. The JUnit 5 equivalent is@Disabled
. If@Ignore
is working for you then my guess is you're running JUnit 4 and not JUnit 5. – Slaw