Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is there any conditional annotation in JUnit to mark few test cases to be skipped?

Tags:

As far as I know to skip a test case the simplest thing to do is to remove the @Test annotation, but to do it over a large number of test cases is cumbersome. I was wondering if there is any annotation available in JUnit to turn off few test cases conditionally.

like image 220
Manoj Avatar asked May 23 '11 10:05

Manoj


People also ask

Which annotation is used for condition based testing?

System Property Conditions Now, if we want to enable our tests based on JVM system properties, we can use the @EnabledIfSystemProperty annotation.

Which annotation helps you to disable a test method?

The best way to disable a test method is to use the @Disabled annotation. @Disabled annotation is used to tell JUnit 5 engine that the annotated test class or test method is currently disabled and should not be executed. Test method will not be executed and will be included in the test report as a disabled test.


2 Answers

Hard to know if it is the @Ignore annotation that you are looking for, or if you actually want to turn off certain JUnit tests conditionally. Turning off testcases conditionally is done using Assume.

You can read about assumptions in the release notes for junit 4.5

There's also a rather good thread here on stack over flow: Conditionally ignoring tests in JUnit 4

like image 119
Kaj Avatar answered Sep 21 '22 09:09

Kaj


As other people put here @Ignore ignores a test.

If you want something conditional that look at the junit assumptions.

http://junit.sourceforge.net/javadoc/org/junit/Assume.html

This works by looking at a condition and only proceeding to run the test if that condition is satisfied. If the condition is false the test is effectively "ignored".

If you put this in a helper class and have it called from a number of your tests you can effectively use it in the way you want. Hope that helps.

like image 41
Jon Avatar answered Sep 23 '22 09:09

Jon