基于seleniumweb自动化测试_p3_补充知识(testng)

上传人:ji****en 文档编号:107674056 上传时间:2019-10-20 格式:PDF 页数:21 大小:1,014.80KB
返回 下载 相关 举报
基于seleniumweb自动化测试_p3_补充知识(testng)_第1页
第1页 / 共21页
基于seleniumweb自动化测试_p3_补充知识(testng)_第2页
第2页 / 共21页
基于seleniumweb自动化测试_p3_补充知识(testng)_第3页
第3页 / 共21页
基于seleniumweb自动化测试_p3_补充知识(testng)_第4页
第4页 / 共21页
基于seleniumweb自动化测试_p3_补充知识(testng)_第5页
第5页 / 共21页
点击查看更多>>
资源描述

《基于seleniumweb自动化测试_p3_补充知识(testng)》由会员分享,可在线阅读,更多相关《基于seleniumweb自动化测试_p3_补充知识(testng)(21页珍藏版)》请在金锄头文库上搜索。

1、基于Selenium的Web自动化测试 P3 补充知识(TestNG) 东软集团股份有限公司 2013年3月12日 Part1 自动化测试入门 Part2 Selenium快速入门 Part3 Web测试补充知识 TestNG入门及进阶 Xpath入门及进阶 Part4 深入学习WebDriver Part5 测试框架设计及应用 此处填写密级标识 概述概述 本章只对TestNG中常用的特性做讲解,完整特性请参考官方文档 http:/testng.org/doc/documentation-main.html TestNG是基于JUnit和Nunit设计思想而构建的一个测试框架,它不仅拥有这些单

2、 元测试框架所有主要特性,而且新增了许多更强大的功能,从而变得更易用、更 适用于从单元测试到集成测试的各类测试工作。 支持注解( Annotations ) 支持多线程测试 灵活的测试用例配置及执行方式 强大的参数化处理能力 支持测试用例的分组和依赖管理 强大的第三方工具支持,包括Eclipse、IDEA、Ant、Maven等 此处填写密级标识 测试用例组织测试用例组织 TestNG的测试用例由Suit、Test、Class、Methods逐级包含组成,通常用XML描述 文件来组织Java测试用例。 此处填写密级标识 常用常用注解(注解(Annotations) 注解注解说明说明 Before

3、Suiterun before all tests in this suite have run. AfterSuiterun after all tests in this suite have run. BeforeTestrun before any test method belonging to the classes inside the tag is run. AfterTestrun after all the test methods belonging to the classes inside the tag have run. BeforeClassrun before

4、 the first test method in the current class is invoked. AfterClassrun after all the test methods in the current class have been run. BeforeMethodrun before each test method. AfterMethodrun after each test method. TestMarks a class or a method as part of the test. ParametersDescribes how to pass para

5、meters to a Test method. DataProviderMarks a method as supplying data for a test method. 此处填写密级标识 通过注解实现“用例分组”通过注解实现“用例分组” 注解注解(属性属性)说明说明 Test(groups)The list of groups this class/method belongs to. Test(dependsOnGroups)The list of groups this method depends on. BeforeGroups(groups)The list of group

6、s that this configuration method will run before. AfterGroups(groups)The list of groups that this configuration method will run after. 此处填写密级标识 通过注解实现“用例依赖”通过注解实现“用例依赖” 注解注解(属性属性)说明说明 Test(dependsOnMethods )The list of methods this method depends on. Test(dependsOnGroups)The list of groups this meth

7、od depends on. Test(alwaysRun)If set to true, this test method will always be run even if it depends on a method that failed. Test(enabled)Whether methods on this class/method are enabled. 此处填写密级标识 通过注解实现“异常断言”通过注解实现“异常断言” 注解注解(属性属性)说明说明 Test(expectedExceptions)The list of exceptions that a test met

8、hod is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure. 通常在针对业务异常测试时,这个功能非常有用。 也就是说通常是断言在指定条件下会出现特定的业务类异常。 此处填写密级标识 通过注解通过注解实现“参数化”实现“参数化”(XML传参)传参) 注解注解(属性属性)说明说明 ParametersDescribes how to pass parameters to a Test method. Param

9、eters(value)The list of variables used to fill the parameters of this method. Optional(default) 指定某个参数是可选的,并且给出默认值 1、Parameters(value)中定义的参数必须在XML中定义,除非定义默认值; 2、Parameters(value)中定义的参数数量和顺序必须与方法入参相同; 此处填写密级标识 通过注解通过注解实现“参数化”实现“参数化”( DataProvider 传传参)参) 注解注解(属性属性)说明说明 Test(dataProvider)The name of th

10、e data provider for this test method. Test(dataProviderClass)he class where to look for the data provider. DataProviderMarks a method as supplying data for a test method. The annotated method must return an Object DataProvider(name)The name of this data provider. DataProvider(parallel)If set to true

11、, tests generated using this data provider are run in parallel. 此处填写密级标识 通过注解通过注解实现“循环调用”实现“循环调用” 注解注解(属性属性)说明说明 Test(invocationCount)The number of times this method should be invoked. 此处填写密级标识 通过注解实现“超时处理”通过注解实现“超时处理” 注解注解(属性属性)说明说明 Test(timeOut)The maximum number of milliseconds this test should t

12、ake. Test(invocationTimeOut )The maximum number of milliseconds this test should take for the cumulated time of all the invocationcounts. 此处填写密级标识 通过注解通过注解实现“并发执行”实现“并发执行” 注解注解(属性属性)说明说明 Test(threadPoolSize, invocationCount) The size of the thread pool for this method. The method will be invoked fro

13、m multiple threads as specified by invocationCount. Note: this attribute is ignored if invocationCount is not specified DataProvider(parallel)If set to true, tests generated using this data provider are run in parallel. 此处填写密级标识 通过通过XML实现“并发执行”实现“并发执行” 通过在testng.xml中配置suite节点的并发相关属性,也可以实现更灵活的并发执 行。

14、节点节点(属性属性)说明说明 suite(parallel)Whether TestNG should use different threads. parallel (false | methods | tests | classes | instances) suite(thread-count) An integer giving the size of the thread pool to use. 此处填写密级标识 常用断言常用断言 方法方法(参数参数)说明说明 assertEquals(actual, expected) Asserts that two objects are e

15、qual. assertFalse(boolean condition) Asserts that a condition is false. assertTrue(boolean condition) Asserts that a condition is true. assertNull(object)Asserts that an object is null. assertNotNull(object)Asserts that an object isnt null. fail(java.lang.String message)Fails a test with the given m

16、essage. 此处填写密级标识 编程方式运行编程方式运行TestNG 最基本的编程方式运行TestNG 通过XmlSuite实现复杂的编程方式运行TestNG 此处填写密级标识 默认报告默认报告 完整报告完整报告 Emailable report EclipseEclipse插件报告插件报告 此处填写密级标识 回顾回顾 通过XML组织用例 全面支持注解 Test Before* After* 断言:assert* 分组:Test(groups) 依赖:Test(dependsOnMethods)、 Test(dependsOnGroups) 参数:Parameters、DataProvider 循环:Test(invocationCount) 并发:Test(threadPoolSize)、DataProvider(parallel) 超时:Test(timeOut)、Test(invocationTimeOut) 异常断

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 电子/通信 > 综合/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号