You can use the Assume class.
A set of methods useful for formulating assumptions about the conditions in which the test makes sense. An unsuccessful assumption does not mean that the code does not work, but the test does not contain any useful information. by default, the JUnit runner considers tests with errors that are ignored.
so at the beginning of the test you can write
Assume.assumeThat("Condition not true - ignoreing test", myPreCondition);
and JUnit will ignore this test if myPreCondition is false.
source share