JUnit @Parameterized函数在测试套件中的@BeforeClass之前运行?

吴睿(Corey Wu):

我正在使用JUnit测试套件来运行一些测试,其中一项使用@Parameterized运行了多次。我发现在运行测试时,@Parameterized函数在@BeforeClass之前运行。这是预期的行为还是正在发生其他事情?我本以为@BeforeClass将在任何测试开始之前运行。

这是我的测试套件:

@RunWith(Suite.class)
@SuiteClasses({ Test1.class, Test2.class })
public class TestSuite {

    @BeforeClass
    public static void setup() throws Exception {
        // setup, I want this to be run before anything else
    }

}

Test1使用@Parameterized:

public class Test1 {

    private String value;

    // @Parameterized function which appears to run before @BeforeClass setup()
    @Parameterized.Parameters
    public static Collection<Object[]> configurations() throws InterruptedException {

        // Code which relies on setup() to be run first

    }

    public Test1(String value) {
        this.value = value;
    }

    @Test
    public void testA() {
        // Test  
    }
}

如何解决此问题,然后再运行其他任何东西,以运行@BeforeClass setup()函数?

NamshubWriter:

不幸的是,这是按预期进行的。JUnit需要在开始测试之前枚举所有测试用例,对于参数化测试,带有注释的方法@Parameterized.Parameters用于确定有多少个测试。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章