相关疑难解决方法(0)

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

我正在使用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
    }

}
Run Code Online (Sandbox Code Playgroud)

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 …
Run Code Online (Sandbox Code Playgroud)

java junit integration-testing automated-tests unit-testing

8
推荐指数
3
解决办法
7017
查看次数

使用@BeforeClass和在JUnit 4 Java中使用实例或静态变量有什么区别?

我是单元测试的新手.关于@BeforeJUnit 4中使用注释的目的.我只是不知道使用它的意义:

public class FoodTestCase {
    static private Food sandwich;

    @BeforeClass
    public static void initialise(){
        sandwich = new Sandwich();    
    }

}
Run Code Online (Sandbox Code Playgroud)

VS

public class FoodTestCase {
    static private Food sandwich = new Sandwich();

}
Run Code Online (Sandbox Code Playgroud)

有什么不同?

java unit-testing junit4

7
推荐指数
1
解决办法
1644
查看次数