如何在testng.xml配置中使用groups标签,实践
来源:互联网 发布:mac怎么切换下载淘宝 编辑:程序博客网 时间:2024/06/06 13:04
由于大量的测试用例,用例本身测试重点不一样。在Testng.xml配置文件进入了group概念,这样用例按照组的方式执行,便于重点考察哪些功能点。 下面就说说实践。
1. 在testng-groups.xml文件中,加入要执行的group
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TC_Operation_Suite" parallel="none" preserve-order="true">
<test name="swiftcoder2_0.TC_Operation">
<groups>
<run>
<include name ="test.workflow" /> //这里配置除@Test annotation 以外,用专门的标注 @Configuration
指定类中的其他特定方法
<include name ="come" /> // 组名come,运行,
<exclude name ="go" /> // 组名go,不运行
</run>
</groups>
<classes>
<class name = "ToBeTestedClass name" /> //在哪个类中执行以上groups
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
注意点:
a. groups必须在test标签里面。(参考文档 :http://www.cnblogs.com/choosewang/articles/3079983.htmlXML文件写法)
b. include name必须在代码中真正存在
2. ToBeTestedClass.java代码
package example1; import org.testng.annotations.*; public class ToBeTestedClass { @BeforeTest@Configuration(beforeTestClass = true,groups = {"test.workflow"}) public void setUp() {System.out.println("----Before Test--------");}
@AfterTest@Configuration(afterTestClass= true, groups = {"test.workflow"})public void TearDown(){System.out.println("----After Test--------");} @Test(groups = { "come" }) public void comeTest() { System.out.println("Hello World"); throw new Error(); } @Test(groups = { "go" }) public void goTest() { System.out.println("Bye Bye"); } @Test(groups = { "come" }) public void comeTestAgain() { System.out.println("Hello World Again"); }
说明点:@BeforeMethod@Configuration(beforeTestMethod= true, groups = {"test.workflow"})public void BeforeMethod() throws InterruptedException{System.out.println("----Before Method--------");}@AfterMethod@Configuration(afterTestMethod= true, groups = {"test.workflow"})public void AfterMethod() throws InterruptedException{System.out.println("----After Method--------");}}
1. @Test注释含有@group注释属于哪一组,如果在testng_group.xml配置include中,则表示运行此组名的所有@Test,反之,exclude表示不执行
2.如果您使用组,那么配置方法也必须属于某个组。详见代码和配置文件背景颜色为紫色的。如果初始条件不配置group的话,这些初始情况是不会执行的
(http://www.ibm.com/developerworks/cn/java/j-testng/
TestNG 使 Java 单元测试轻而易举(查看配置方法内容))
3. 了解@Configuration annotation的使用(http://www.ibm.com/developerworks/cn/java/j-test-ng/Eclipse 3.1 中使用TestNG:基于注释的单元测试框架
清单3 configuration中的属性)其他参考文档:
http://www.ibm.com/developerworks/cn/java/j-lo-testng/
使用 TestNG 的新特性管理实际项目中的大量单元测试
http://testng.org/doc/documentation-main.html#test-groups
Testng官网文档
3. 执行Testng_groups.xml文件:
类似
[TestNG] Running:
E:\Documents\QA.Management\automation\swiftcoder2_0\testng-groups.xml
Hello World
Hello World Again!
===============================================
TC_Operation_Suite
Total tests run: 2, Failures: 0, Skips: 0
===============================================
- 如何在testng.xml配置中使用groups标签,实践
- 在testng.xml文件中配置TestNG 的依赖关系
- TestNG配置testng.xml
- 在Eclipse中使用Maven配置WebDriver+Testng(一)
- 在Eclipse中使用Maven配置WebDriver+Testng(二)
- TestNG中组groups概念以及用法
- testNG 使用配置,关于not xml问题解决
- Android 在string.xml中使用标签
- eclipse中testng的配置和使用
- eclipse中testng的配置和使用
- TestNG.xml参数配置-如何控制部分执行@test方法
- 在STRUTS中如何使用 标签
- 如何在网页中使用H1标签
- xml如何在IIS配置中恢复
- log4j在web.xml中如何配置
- Spring 如何在xml中配置Bean?
- TestNG的testng.xml配置概述
- struts2标签应用 需在web.xml中 配置
- java cloassLoader大仙儿
- coredata基本用法(二)
- js获取各种屏幕高度
- Oracle创建表空间、创建用户以及授权、查看权限
- Longest increasing subsequence |LeetCode
- 如何在testng.xml配置中使用groups标签,实践
- button设置点击更改背景图片
- 苦并快乐着—兄弟连IT教育
- JavaWeb初学第一回合
- Linux系统启动任务的写法
- iOS开发 - Xcode SVN提交字母示意
- codeforce 596B
- proguard混淆打jar包
- java通过反射Method、属性字段名、值、数据类型