TestNg依赖高级用法之强制依赖与顺序依赖------TestNg依赖详解(二)
2014-10-22 18:03
465 查看
原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
TestNg使用dependsOnGroups属性来进行依赖测试,
测试方法依赖于某个或某些方法,这个/这些方法作为前置依赖条件
强制依赖:如果被依赖的某一个方法发生了异常,那么之后的方法都不会被执行(默认)
顺序依赖:无论被依赖的方法是否出现异常,后续的方法都会被执行,通过alwaysRun=“true”来配置
配置文件:
运行结果:我们发现在配置了顺序依赖之后,即使initEnvironment()方法抛出了异常,method1()还是执行了并且passed
默认的强制依赖:Java code:
原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
运行结果: 这时我们发现initEnvironment() 抛出异常后, method1() 被跳过了,并没有被执行
TestNg使用dependsOnGroups属性来进行依赖测试,
测试方法依赖于某个或某些方法,这个/这些方法作为前置依赖条件
强制依赖:如果被依赖的某一个方法发生了异常,那么之后的方法都不会被执行(默认)
顺序依赖:无论被依赖的方法是否出现异常,后续的方法都会被执行,通过alwaysRun=“true”来配置
/** * * <p> * Title: TestngDependOnGroups * </p> * * <p> * Description: 测试方法依赖于某个或某些方法,这个/这些方法作为前置依赖条件 * * 如果依赖的方法发生异常而不能正确的执行时,默认情况下,接下来的方法将不会被执行(强制依赖,默认) 如果在方法体的注解上设置了alwaysRun = * true,那么此时在依赖链中的任何一个方法出现异常都不会影响其它方法的执行 * * dependsOnGroups * * </p> * * <p> * Company: * </p> * * @author : Dragon * * @date : 2014年10月21日 */ public class TestngDependOnGroups { @Test(groups = { "init" }) public void serverStartedOk() { System.out.println("serverStartedOk....."); } @Test(groups = { "init2" }) public void initEnvironment() { System.out.println("initEnvironment....."); throw new RuntimeException("unexpected fail......"); } @Test(dependsOnGroups = { "init.*" }, alwaysRun = true) public void method1() { System.err.println("I am over here....."); } }
配置文件:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="framework_testng" > <test verbose="2" name="TestngDependOnGroups"> <classes> <class name="com.dragon.testng.annotation.TestngDependOnGroups"> </class> </classes> </test> </suite>
运行结果:我们发现在配置了顺序依赖之后,即使initEnvironment()方法抛出了异常,method1()还是执行了并且passed
initEnvironment..... serverStartedOk..... I am over here..... PASSED: serverStartedOk PASSED: method1 FAILED: initEnvironment java.lang.RuntimeException: unexpected fail...... at com.dragon.testng.annotation.TestngDependOnGroups.initEnvironment(TestngDependOnGroups.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) =============================================== TestngDependOnGroups Tests run: 3, Failures: 1, Skips: 0 ===============================================
默认的强制依赖:Java code:
public class TestngDependOnGroups { @Test(groups = { "init" }) public void serverStartedOk() { System.out.println("serverStartedOk....."); } @Test(groups = { "init2" }) public void initEnvironment() { System.out.println("initEnvironment....."); throw new RuntimeException("unexpected fail......"); } @Test(dependsOnGroups = { "init.*" }) public void method1() { System.err.println("I am over here....."); } }
原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
运行结果: 这时我们发现initEnvironment() 抛出异常后, method1() 被跳过了,并没有被执行
initEnvironment..... serverStartedOk..... PASSED: serverStartedOk FAILED: initEnvironment java.lang.RuntimeException: unexpected fail...... at com.dragon.testng.annotation.TestngDependOnGroups.initEnvironment(TestngDependOnGroups.java:41) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84) at org.testng.internal.Invoker.invokeMethod(Invoker.java:714) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) at org.testng.TestRunner.privateRun(TestRunner.java:767) at org.testng.TestRunner.run(TestRunner.java:617) at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) at org.testng.SuiteRunner.run(SuiteRunner.java:240) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224) at org.testng.TestNG.runSuitesLocally(TestNG.java:1149) at org.testng.TestNG.run(TestNG.java:1057) at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175) SKIPPED: method1 =============================================== TestngDependOnGroups Tests run: 3, Failures: 1, Skips: 1 ===============================================
TestNg依赖详解(三)------灵活的文件配置依赖
相关文章推荐
- TestNg依赖高级用法之强制依赖与顺序依赖------TestNg依赖详解(二)
- TestNg配置依赖的高级用法------依赖详解(三)
- TestNg依赖配置基础用法(单一方法依赖)------TestNg依赖详解(一)
- TestNg依赖配置基础用法(单一方法依赖)------TestNg依赖详解(一)
- PHP的switch判断语句的“高级”用法详解
- awk的详解 基本用法和高级用法
- String.replace高级用法详解
- 转高手详解:sscanf函数的高级用法
- <转>jQuery动画高级用法(上)——详解animation中的.queue()函数
- Java中初始化对象的顺序,静态代码块的用法以及Static的用法详解
- Curl高级用法详解
- makefile详解 变量高级用法 追加变量值
- [转载]jQuery动画高级用法——详解animation中的.queue()函数
- jQuery动画高级用法(上)——详解animation中的.queue()函数 http://www.cnblogs.com/hh54188/archive/2011/04/09/1996469.
- java中静态代码块的用法 static用法详解 类的加载顺序
- PHP的switch判断语句的“高级”用法详解
- jQuery动画高级用法(上)——详解animation中的.queue()函数
- jQuery动画高级用法——详解animation中的.queue()函数
- enum以及位域运算符的高级用法(详解-最易理解位域运算的教程)
- linux sync命令参数及用法详解---强制把内存数据写入硬盘命令