Is there any way to conditionally ignore a test wi

2019-06-09 13:18发布

问题:

This question already has an answer here:

  • Conditionally ignoring tests in JUnit 4 4 answers

I have an integration test that fetches from a 3rd party API, I'd like to only run this test class manually, is there any way I can ignore the test unless an argument/parameter/env variables is passed? So I can run the test manually with my IDE, but have CI ignore it.

Worth saying that I have unit tests that test smaller portions of the workload that can always run.

回答1:

With Junit Assume:

public class SomeTest {
    @Before
    public void before() throws Exception {
        Assume.assumeTrue("someValue".equals(System.getProperty("some.property")));
    }

    // add your @Test
}

You could also use @IfProfileValue for tests using spring junit runner