配置型的依赖测试,让依赖测试不局限于测试代码中,在XML文件中进行灵活的依赖配置
原创文章,版权所有,允许转载,标明出处:http://blog.csdn.net/wanghantong
Javacode:
- /**
- *
- * <p>
- * Title: TestngDependencyOnXML
- * </p>
- *
- * <p>
- * Description: 不使用注解的情况下,通过对testng-xml来进行依赖配置
- *
- * 执行原则:
- * 被依赖的group最先执行,如果某个group没有被配置成被依赖,那么它将在被依赖的group之后执行,最后执行的是需要依赖其它group的方法
- * ,如果都没有配置依赖,则按顺序执行.一个方法有多个依赖时用空格隔开
- * </p>
- *
- * <p>
- * Company:
- * </p>
- *
- * @author : Dragon
- *
- * @date : 2014年10月21日
- */
- public class TestngDependencyOnXML {
- @Test(groups = { "ss" })
- public void a() {
- System.out.println("this is method a, Groups ss");
- }
- @Test(groups = { "ss" })
- public void b() {
- System.out.println("this is method b, Groups ss");
- }
- @Test(groups = { "xx" })
- public void c() {
- System.out.println("this is method c ,Groups xx");
- }
- @Test(groups = { "xx" })
- public void d() {
- System.out.println("this is method d, Groups xx");
- }
- @Test(groups = { "yy" })
- public void e() {
- System.out.println("this is method e , Groups yy");
- }
- }
配置文件:
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
- <suite name="framework_testng">
- <test name="testng-dependOnXML" >
- <groups >
- <dependencies >
- <group name="ss" depends-on="xx yy" />
- </dependencies>
- </groups>
- <classes>
- <class name="com.dragon.testng.annotation.TestngDependencyOnXML" />
- </classes>
- </test>
- </suite>
运行结果:
- this is method c ,Groups xx
- this is method d, Groups xx
- this is method e , Groups yy
- this is method a, Groups ss
- this is method b, Groups ss
- ===============================================
- framework_testng
- Total tests run: 5, Failures: 0, Skips: 0
- ===============================================
总结: 被依赖的group最先执行,如果某个group没有被配置成被依赖,那么它将在被依赖的group之后执行,最后执行的是需要依赖其它group的方法,如果都没有配置依赖,则按顺序执行.一个方法有多个依赖时用空格隔开