• (十一)TestNG 其他使用技巧


    除了前面介绍的功能外,TestNG 还有一些使用技巧,相对比较简单,这里通过一个例子来演示。

    其它使用技巧


    import org.testng.annotations.Test;
    import static org.testng.AssertJUnit.assertEquals;
    
    
    public class OtherTest {
    
        // 该条用例跳过执行
        @Test(enabled = false)
        publicvoidtestCase1(){
            assertEquals(2+2, 4);
        }
    
        // 设定用例超时时间
        @Test(timeOut = 3000)
        publicvoidtestCase2()throws InterruptedException {
            Thread.sleep(3001);
        }
    
        // 预设用例抛出的异常类型
        @Test(expectedExceptions = RuntimeException.class)
        publicvoidtestCase3(){
            assertEquals(2/0,1);
        }
    
    }
    
    • enabled 设置用例是否跳过执行,默认为:true ,表示不跳过。false 表示跳过执行。

    • timeOut 设置用例运行的超时间,3000 单位为毫秒,当用例运行时间超过 3000 毫秒则判定为失败。不管用例本身是否运行失败。

    • expectedExceptions 用来预设用例运行会出现的异常。例如 2/0 将会抛出 RuntimeException 类型的异常,如果出现异常则表示用例执行成功。

  • 相关阅读:
    linux安装lamp/lamp/lanmp
    git命令
    redis常问面试题
    liunx 项目发布(django + uwsgi + nginx+supervisor发布web服务器)
    安装nginx
    liunx安装mysql(mariadb)
    linux安装python3
    scrapy框架day01
    网络编程, socket用法
    面向对象进阶
  • 原文地址:https://www.cnblogs.com/xinlan06/p/11498789.html
Copyright © 2020-2023  润新知