测试框架TestNg2-忽略测试,分组测试,异常测试,依赖测试,超时测试

忽略测试

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);

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值