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

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.

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.

You can use the @Ignore annotation which you can add to a single test or test class to deactivate it. If you need something conditional, you will have to create a custom test runner that you can register using @RunWith(YourCustomTestRunner. Class) You could use that to define a custom annotation which uses expression language or references a system property to check whether a test should be run.

But such a beast doesn't exist out of the box.

Don't know if he edited his question, but @Ignore is not conditional. – Alan Escreet May 23 '11 at 10:58 @Alan if I get the OP right, his interpretation of conditional is "whether he adds the annotation or not" :-) – Sean Patrick Floyd May 23 '11 at 10:59 True. I guess we'll find out when he accepts an answer.

– Alan Escreet May 23 '11 at 11:10 I'm sorry if I wasn't clear, by conditional I meant something like @RunIf(boleanExpression). But it seems such a thing is not available. – Manoj May 23 '11 at 11:22.

As other people put here @Ignore ignores a test. If you want something conditional that look at the junit assumptions. junit.sourceforge.net/javadoc/org/junit/... 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.

If you use JUnit 4. X, just use @Ignore. See here.

Don't know if he edited his question, but @Ignore is not conditional. – Alan Escreet May 23 '11 at 10:58.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions