TestNG忽略测试和超时测试
来源:互联网 发布:梦里花落知多少对应句 编辑:程序博客网 时间:2024/05/22 08:29
TestNG忽略测试
有时,我们的代码是没有准备好,如果测试用例写入到测试方法/代码将无法运行,在这种情况下,@Test(enabled = false)有助于禁用此测试用例执行
使用例子
public class TestEnable { @Test public void testcase1(){ System.out.println("testcase1"); } @Test(enabled = false) public void testcase2(){ System.out.println("testcase2"); } @Test public void testcase3(){ System.out.println("testcase3"); }}
运行结果
[TestNG] Running: C:\Users\Administrator\.IntelliJIdea2016.3\system\temp-testng-customsuite.xmltestcase1testcase3
从上面可以看到testcase2已经被忽略掉了
TestNG超时测试
当一个测试用例里面有某些部分会导致耗时异常,比如里面有个循环,导致死循环,那么我们不可能一直在这个测试用例等待这个用例运行,我们可以设定预定的用例执行最大时间,超出这个时间,这个用例就认为失败,接着运行下面的测试用例。
达到这个目的,我们可以使用@Test(timeout=)来实现
使用例子
public class TestTimeOut { @Test(timeOut = 1000) public void testcase1(){ try { Thread.sleep(999); System.out.println("testcase1"); } catch (InterruptedException e) { e.printStackTrace(); } } @Test(timeOut = 1000) public void testcase2(){ try { Thread.sleep(2000); System.out.println("testcase2"); } catch (InterruptedException e) { e.printStackTrace(); } } @Test public void testcase3(){ System.out.println("testcase3"); }}
运行结果
[TestNG] Running: C:\Users\Administrator\.IntelliJIdea2016.3\system\temp-testng-customsuite.xmltestcase1java.lang.InterruptedException: sleep interrupted at java.lang.Thread.sleep(Native Method) at com.testproj.Demo.TestTimeOut.testcase2(TestTimeOut.java:22) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:46) at org.testng.internal.InvokeMethodRunnable.run(InvokeMethodRunnable.java:37) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)org.testng.internal.thread.ThreadTimeoutException: Method org.testng.internal.TestNGMethod.testcase2() didn't finish within the time-out 1000 at java.lang.Throwable$PrintStreamOrWriter.<init>(Throwable.java:728) at java.lang.Throwable$PrintStreamOrWriter.<init>(Throwable.java:728) at java.lang.Throwable$WrappedPrintStream.<init>(Throwable.java:739) at java.lang.Throwable.printStackTrace(Throwable.java:643) at java.lang.Throwable.printStackTrace(Throwable.java:634) at com.testproj.Demo.TestTimeOut.testcase2(TestTimeOut.java:25) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) at org.testng.internal.InvokeMethodRunnable.runOne(InvokeMethodRunnable.java:46) at org.testng.internal.InvokeMethodRunnable.run(InvokeMethodRunnable.java:37) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)testcase3===============================================Default SuiteTotal tests run: 3, Failures: 1, Skips: 0===============================================
完成
0 0
- TestNG忽略测试和超时测试
- TestNG忽略测试
- testng忽略测试
- testng超时测试
- 软件测试实习0624-testNG忽略测试
- TestNG 教程3 – 忽略测试方法
- TestNG 学习总结 - 忽略测试(八)
- Testng 如何忽略测试类class
- TestNG 教程4 – 超时测试
- 测试工具Selenium和TestNG
- TestNG的组测试和组中组测试
- TestNG的组测试和组中组测试
- TestNG的组测试和组中组测试
- Android Monkey测试入门-8-Monkey高级参数之忽略崩溃和超时
- 忽略测试
- testNG测试配置文件testng.xml
- 基于Selenium2和TestNG的自动化测试
- 基于Selenium2和TestNG的自动化测试
- JAVA并发编程
- Leetcode 166 Fraction to Recurring Decimal
- c++的应用领域是哪些?
- Android高效加载大图、多图解决方案,有效避免程序OOM(1)
- 使用 macport 安装django
- TestNG忽略测试和超时测试
- texturepacker 用命令行批处理
- STM-32中的中断
- const
- 18、Power Query-SQL筛选
- navbar (Bootstrap)
- c#简单打字游戏
- GOF23的一些总结(二十一)
- Login/index.html