0

我尝试从我的main()方法运行 junit:

    public static void main(String... args) throws ClassNotFoundException, IOException {
...
logger.debug("className " + className + "methodName " + methodName);

        Request request = Request.method(Class.forName(className), methodName);
        return new JUnitCore().run(request);
}

这是我的TestClass。

当我没有@BeforeClass方法时,它被称为 OK

但是当我添加@BeforeClass这条线时没有进入setup()方法(我尝试调试)

//    @BeforeClass
//    public void classSetup()
//    {
//        logger = new Logger();
//        stringUtils = new StringUtils(logger);
//    }

    @Before
    public void setup() {

        logger = new Logger();
        stringUtils = new StringUtils(logger);

    }


    @Test
    public void test1() throws Exception {..}

}
4

1 回答 1

0

带有@BeforeClass 注解的方法应该是静态的。

在您的情况下,classSetup 方法应该是静态的。

@BeforeClass
public static void classSetup(){
    logger = new Logger();
    stringUtils = new StringUtils(logger);
}
于 2014-12-16T15:08:18.813 回答