3

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?

jlars62
  • 7,183
  • 7
  • 39
  • 60
  • 2
    You should be able to control which tests are run/skipped in maven and Eclipse using [JUnit 4 categories](http://junit.org/javadoc/4.9/org/junit/experimental/categories/Categories.html). There is some discussion of this in http://stackoverflow.com/questions/3100924/how-to-run-junit-tests-by-category-in-maven – nbrooks Jun 03 '14 at 01:00
  • @nbrooks I found a different solution for now but categories were good to learn about. Thanks! – jlars62 Jun 04 '14 at 19:14

1 Answers1

3

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.

jlars62
  • 7,183
  • 7
  • 39
  • 60