忽略测试
Enabled参数
@Test(enabled = false) public void ignore2(){ System.out.println("========2========"); }
组测试中方法分组测试
@Test(groups = "server")
@BeforeGroups("server") public void beforeGroupOnServer(){ System.out.println("before group on server======"); }
组测试中类分组测试
@Test(groups = "stu") public class GroupOnClass1 {}
异常测试
@Test(expectedExceptions = RuntimeException.class)
期望结果为某个异常时
失败异常
@Test(expectedExceptions = RuntimeException.class)
public void runTimeFailed(){
System.out.println("这是一个失败的测试用例===========");
}
//成功异常
@Test(expectedExceptions = RuntimeException.class)
public void runTimeSuccess(){
System.out.println("这是一个成功的测试用例===========");
throw new RuntimeException();
}
依赖测试
@Test(dependsOnMethods = {"test1"},alwaysRun= true)
public class DependTest { @Test public void test1(){ System.out.println("test----------1------"); throw new RuntimeException(); } @Test(dependsOnMethods = {"test1"},alwaysRun= true) public void test2(){ System.out.println("test---------2------"); } }
超时测试
@Test(timeOut = 3000)
public void testFailed() throws InterruptedException {
Thread.sleep(4000);
}