Excluding a non param test in parameterized test c

2019-01-13 20:00发布

Is there any annotation in JUnit to exclude a non param test in parameterized test class?

8条回答
Summer. ? 凉城
2楼-- · 2019-01-13 20:43

I did something similar to Matthew's Solution. However, I created two new java files that extends the current file so that the ComponentSingleTests do not run twice. This way, they can share common member variables and helper methods from the parent class. The problem I had with Matthew's Solution was that my single test was running twice instead of once as the Enclosed.class (which extends the Suite.class) will make your test run twice as described in this link Prevent junit tests from running twice

ComponentTest.java

public class ComponentTest {
    public int sharedMemberVariables; 
    ... 
}

ComponentParamTests.java

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class ComponentParamTests extends ComponentTest {

    @Parameters
    ...

    @Test
    public void testCaseUsingParams() throws Exception {
    }
}

ComponentSingleTests.java

import org.junit.Test;

public class ComponentSingleTests {

    @Test
    public void testCaseWithoutParams() throws Exception {
        ...
    }
}
查看更多
太酷不给撩
3楼-- · 2019-01-13 20:45

I just found out that one can use JUnitParams. I converted one of my tests now to use it and it works beautifully.

查看更多
登录 后发表回答