Assumptions and Conditional Test execution, ignoring in JUnit

Sometime you want to ignore some test depends on environment settings. Now both JUnit 4 and JUnit 5 support the concept of assumptions.

Unit Test like this:

1
2
3
4
5
6
7
@Test
public void testRun() {

Assume.assumeTrue(BooleanUtils.toBoolean(System.getProperty("runtest")));

// Rest of testcase
}

With Gradle, pass in parameter like this:

1
$ gradle test -Pruntest=false

References

Contents