JUnit conveniently lets you annotate a test method with @Ignore.
@Test @Ignore public void testAdd() { ... }
This causes JUnit to completely ignore the method.
What if you want to only ignore the test under a condition determined at runtime? This would be nice:
@Test @Ignore(someCondition()) public void testAdd() { ... }
But Java and JUnit do not work like that. Instead, you need to use the Assume class.
@Test public void testAdd() { Assume.assumeTrue(someCondition()); ... }
Voila!
Pingback: The Art of Test Driven Development: Running unit tests conditionally | Gary Gregory