我发现当我执行多个JUnit测试时静态块只运行一次.如何强制它为每个测试方法运行?我正在使用最新的JUnit 4.8.2
另外,根据xUnit设计原则,每种方法都应该完全独立于其他方法.为什么静态块只执行一次?
@Test TestMethod1 () {
Accounts ac = new Accounts();
ac.method1(); //kill the thread inside
}
@Test TestMethod2 () {
Accounts ac = new Accounts();
ac.method2(); // the thread is no longer available!!
}
class Accounts {
static {
// initalize one thread to monitor something
}
}
Run Code Online (Sandbox Code Playgroud)
当TestMethod1和TestMethod2位于不同的测试类中时,甚至会发生这种情况.