相关疑难解决方法(0)

Java jUnit:在任何测试类之前运行的测试套件代码

我有一个测试套件类:

@RunWith(Suite.class)
@Suite.SuiteClasses({
    GameMasterTest.class,
    PlayerTest.class,
})
public class BananaTestSuite { 
Run Code Online (Sandbox Code Playgroud)

在包含实际测试的任何类之前,我需要使用什么注释来在此类中运行函数?现在,我正在这样做,它可以工作,但它不是那么可读:

static {
    try {
        submitPeelAction = new Player(new GameMaster(1)).getClass().getDeclaredMethod("submitPeelAction");
    } catch (SecurityException e) {
        e.printStackTrace();
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }
    submitPeelAction.setAccessible(true);
}
Run Code Online (Sandbox Code Playgroud)

我试过@BeforeClass但它没用.

java junit unit-testing

20
推荐指数
2
解决办法
3万
查看次数

标签 统计

java ×1

junit ×1

unit-testing ×1