我对Idea 14和JUnit有疑问。我无法按正确的顺序运行@BeforeClass和@AfterClass方法(在所有测试之前和所有测试之后)。每次订单都不同。我试图重新安装IDEA,删除所有设置但没有任何作用。请帮忙。这是我的测试代码的示例:
package com.rent.test;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import static org.junit.Assert.*;
import org.junit.Test;
public class testnewTest {
static int num;
static int num1;
@BeforeClass
public static void OnceExecutedBeforeAll() {
System.out.println("@BeforeClass: onceExecutedBeforeAll");
num = 15;
num1 = 16;
}
@AfterClass
public static void after() throws Exception {
System.out.println("End");
}
@Test
public void testLogin() throws Exception {
System.out.println("test");
assertEquals(15, num);
}
@Test
public void testGetOrdersDate() throws Exception {
System.out.println("test2");
assertEquals(16, num1);
}
}
这是输出:
test2
@BeforeClass: onceExecutedBeforeAll
test
End
答案 0 :(得分:3)
您可能观察到的事实是输出并不总是在终端中同步。测试本身正在以正确的顺序运行。
如果他们不是,那么test2
会出现失败,因为看起来你的@BeforeClass
方法后来 。