MyTest
每种测试方法的新实例
对于每种测试方法,将创建Junit的行为的 新实例
MyTest。
因此,在您的情况下,这两种方法的变量
count都将具有value
1,因此这两种测试方法的值都
count++将是
2,因此测试用例将通过。
public class MyTest{ public MyTest(){ // called n times System.out.println("Constructor called for MyTest"); } @Before //called n times public void setUp(){ System.out.println("Before called for MyTest"); } //n test methods}如果您使用2种测试方法执行上述代码:
输出将是:
Constructor called for MyTestBefore called for MyTest//test executionConstructor called for MyTestBefore called for MyTest



