基本标签、依赖、异常、忽略、超时
public class BasicAnnotation {
//最基本的注解,用来把方法标记为测试的一部分
@Test
public void testCase1(){
System.out.printf("Thread Id : %s%n",Thread.currentThread().getId());
System.out.println("Test这是测试用例1");
}
@Test
public void testCase2(){
System.out.printf("Thread Id : %s%n",Thread.currentThread().getId());
System.out.println("Test这是测试用例2");
}
@BeforeMethod
public void beforeMethod(){
System.out.println("BeforeMethod这是在测试方法之前运行的");
}
@AfterMethod
public void afterMethod(){
System.out.println("AfterMethod这是在测试方法之后运行的");
}
@BeforeClass
public void beforeClass(){
System.out.println("beforeClass这是在类运行之前运行的方法");
}
@AfterClass
public void afterClass(){
System.out.println("afterClass这是在类运行之后运行的方法");
}
@BeforeSuite
public void beforeSuite(){
System.out.println("BeforeSuite测试套件");
}
@AfterSuite
public void afterSuite(){
System.out.println("AfterSuite测试套件");
}
}
public class DependTest {
@Test
public void test1(){
System.out.println("test1 run");
throw new RuntimeException();
}
@Test(dependsOnMethods = {"test1"})
public void test2(){
System.out.println("test2 run");
}
}
public class ExpectedException {
/**
* 什么时候会用到异常测试??
* 在我们期望结果为某一个异常的时候
* 比如:我们传入了某些不合法的参数,程序抛出了异常
* 也就是说我的语气结果就是这个异常。
*/
// 这是一个测试结果会失败的异常测试
@Test(expectedExceptions = RuntimeException.class)
public void runTimeExceptionFailed(){
System.out.println("这是一个失败的异常测试");
}
// 这是一个成功的异常测试
@Test(expectedExceptions = RuntimeException.class)
public void runTimeExceptionSuccess(){
System.out.println("这是我的异常测试");
throw new RuntimeException();
}
}
public class IgnoreTest {
@Test
public void ignore1(){
System.out.println("ignore1 执行!");
}
@Test(enabled = false)
public void ignore2(){
System.out.println("ignore2 执行");
}
@Test(enabled = true)
public void ignore3(){
System.out.println("ignore3 执行");
}
}
public class TimeOutTest {
@Test(timeOut = 3000)//单位为毫秒值
public void testSuccess() throws InterruptedException {
Thread.sleep(2000);
}
@Test(timeOut = 2000)
public void testFailed() throws InterruptedException {
Thread.sleep(3000);
}
}
基本标签、依赖、异常、忽略、超时public class BasicAnnotation { //最基本的注解,用来把方法标记为测试的一部分 @Test public void testCase1(){ System.out.printf("Thread Id : %s%n",Thread.currentThread().getId()); ...