How to make JUnit ignore a specific test case at runtime when starting with a parameterized runner?

Possible duplicate:
Conditionally ignoring tests in JUnit 4

I have a set of system tests that run with Parameterizedrunner and that I would like to run in different environments. Some of the tests should only be run in non-production environments, and when I go into production, I would like them to be ignored, so I'm looking for a way to say:

@Test
public void dangerousTest() {
    if (isProduction(environment)) ignore(); // JUnit doesn't provide ignore()
    environment.launchMissilesAt(target);
    assertThat(target, is(destroyed()));
}

The problem is that JUnit does not provide a method ignore()to ignore the test case at runtime. Also Assume.assumeTrue(isNotProduction(environment)), it doesn't seem to work with Parameterizedrunner - it just marks the tests as passed, not ignored. Any ideas on how something equivalent can be achieved with limitations that:

  • You must use Parameterizedrunner in the set
  • should tests appear ignored if the package is launched during production?
+5
source share
2 answers

You can always do

if (isProduction(environment)) return;

The test will be marked as passed, but at least the missiles will not be launched.

Assume, , :

, . , , . JUnit . -. :

, :

@Test
public void dangerousTest() {
    assumeTrue(!isProduction(environment));
    // ...
}
+5

:

, , , . , , : .

, , . , , , .

  • TestNG, . "production":

    @Test(groups = "production")
    public void dangerousTest() { ... }
    

, "production".

+1

All Articles