依赖`
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
(依赖中最好保持版本号一致)
注释
@Test:将一个方法标记为测试方法,写在方法名上,@ Test提供了两个参数
1,“expected”,定义测试方法应该抛出的异常,如果测试方法没有抛出异常或者抛出了一个不同的异常,测试失败
2,“timeout”,如果测试运行时间长于该定义时间,测试失败(单位为毫秒)
@Test(timeout = 5000)
public void fun6() {
("TestFun6");
}
@Test(expected = )
public void fun7() throws Exception{
throw new Exception();
}
@Before:标注方法之后,表示这个方法在类中的其余方法调用前必调用,通常与@After配合使用
@After:与@Before相反,表示这个方法在类中的其余方法调用后必调用
@BeforeClass:在测试类没有实例化之前就已被加载,需用static修饰,类中所有测试方法调用前执行一次,通常与AfterClass配合使用
@AfterClass:与@BeforeClass相反,在测试类没有实例化之前就已被加载,需用static修饰,类中所有测试方法调用后执行一次
@Ignore:标注该方法或者类不执行,可标注在方法或者类上
@RunWith()定义继承类之间的运行顺序
@RunWith()
@({
,
})
public class suitTest {
}