Java 为什么我的@BeforeClass块junit会运行?

Java 为什么我的@BeforeClass块junit会运行?,java,testing,junit,e2e-testing,Java,Testing,Junit,E2e Testing,我尝试从我的main()方法运行junit: public static void main(String... args) throws ClassNotFoundException, IOException { ... logger.debug("className " + className + "methodName " + methodName); Request request = Request.method(Class.forName(className

我尝试从我的
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);
}
这是我的测试课

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

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


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

@BeforeClass
public static void classSetup(){
    logger = new Logger();
    stringUtils = new StringUtils(logger);
}
在您的情况下,classSetup方法应该是静态的

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

所以
logger
stringUtils
也必须是静态的。奇怪的是,logger可能不是测试类的实例成员