相关疑难解决方法(0)

如何在每个测试方法中强制运行静态块?

我发现当我执行多个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)

TestMethod1TestMethod2位于不同的测试类中时,甚至会发生这种情况.

java junit unit-testing

9
推荐指数
1
解决办法
8455
查看次数

标签 统计

java ×1

junit ×1

unit-testing ×1