jlars62
jlars62

Reputation: 7353

Tell Eclipse to skip tests

Is there a way to tell only Eclipse to skip various individual junit tests (but still run the rest of them)? I am familiar with the @Ignore annotation, but that is not what I am looking for because that will cause the tests to always be skipped.

I would like the tests to be skipped when ran by eclipse (Run As -> Junit Test) but ran in any other context, most likely during a maven build.

Any ideas?

Upvotes: 3

Views: 2652

Answers (1)

jlars62
jlars62

Reputation: 7353

So far the following solution has worked well. It is not a complete solution because it causes the tests to only be ran by maven when maven is invoked from the command line. For now though, it works.

When maven is invoked, the maven command line arguments are placed in the environment map (System.getenv()). When the tests are run through jUnit in eclipse, there is no entry in System.getenv() for the maven command line arguments. So, I am using jUnits Assume class to check that this property is not null for the tests that I want eclipse to skip.

Code:

Assume.assumeNotNull(System.getenv("MAVEN_CMD_LINE_ARGS"));

FYI, one downside of this solution is that eclipse marks the tests as passed instead of skipped.

Upvotes: 3

Related Questions