Include and Exclude Test Methods in TestNG
来源:互联网 发布:网络购票如何买下铺 编辑:程序博客网 时间:2024/05/22 13:15
Forward from:http://www.seleniumeasy.com/testng-tutorials/include-exclude-test-methods-in-testng
TestNg provides an option to include or exclude Groups, Test Methods, Classes and Packages using include and exclude tags by defining in testng.xml.
First we will create an examples to use include and exclude tags for Test Methods in a class.
We will create a Class with three Test Methods. In that we will include two test methods and try to exclude one test method.
Below is the example class file with three test methods
package com.easy.entry;import org.testng.annotations.Test;public class AddTestCase {@Testpublic void addLocationTestCase() {System.out.println("Im in add location test case");}@Testpublic void addDepartmentTestCase() {System.out.println("Im in add department test case");}@Testpublic void addEmployeeTestCase() {System.out.println("Im in add employee test case");}}
In the above class example, we have created three test methods, 'addLocationTestCase', 'addDepartmentTestCase', and
'addEmployeeTestCase'.
In the below testng.xml file we will exclude 'addEmployeeTestCase' and try to execute the program. We need to first add the class name and in that class , we need to define the methods which needs to be included and excluded
<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" "="" style="box-sizing: border-box; color: rgb(51, 122, 183); text-decoration: none; background-color: transparent;">http://testng.org/testng-1.0.dtd" ><suite name="Sample Test Suite" verbose="1" > <test name="Method Test Cases" > <classes> <class name="com.easy.entry.AddTestCase"> <methods> <include name="addLocationTestCase" /> <include name="addDepartmentTestCase" /> <exclude name="addEmployeeTestCase" /> </methods> </class> </classes> </test></suite>
After running the above testng.xml file, we will get the output as below. It will just run the test methods which are included in the class. And will not execute the test methods which are in excluded.
Here as in the above xml file, we can also just mention test methods which you want to exclude. If say there are 20 test methods in a class, and if you just want to exclude one or two test methods, you can just have exclude tag with test methods without again adding all the other tests methods using include tag.
Look at the below xml file to exclude only the particular test methods which are needed. In the below example, we are trying to exclude only one test method. And all the test methods in a class will get executed by default.
<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" "="" style="box-sizing: border-box; color: rgb(51, 122, 183); text-decoration: none; background-color: transparent;">http://testng.org/testng-1.0.dtd" ><suite name="Sample Test Suite" verbose="1" > <test name="Method Test Cases" > <classes> <class name="com.easy.entry.AddTestCase"> <methods> <exclude name="addEmployeeTestCase" /> </methods> </class> </classes>
Below is the same output which is generated.
Here again same as above, if you just want to execute only one or two test methods, we can simply mention only those test methods in the testng.xml file. Only those test methods will be executed and all the rest test methods will not be executed.
Look at the below xml file to include only particular test methods
<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" "="" style="box-sizing: border-box; color: rgb(51, 122, 183); text-decoration: none; background-color: transparent;">http://testng.org/testng-1.0.dtd" ><suite name="Sample Test Suite" verbose="1" > <test name="Method Test Cases" > <classes> <class name="com.easy.entry.AddTestCase"> <methods> <include name="addDepartmentTestCase" /> </methods> </class> </classes> </test></suite>
Below is the same output which is generated. Even though there are three test methods in the class, we are trying to execute only one particular test method by specifying the test method in include tag.
In the same way we can also use include and exclude tags for Groups, Classes and Packages
- Include and Exclude Test Methods in TestNG
- testng翻译之五--Test methods, Test classes and Test groups
- Robot: Include and Exclude Tags
- How to Test Private and Protected methods in .NET
- TestNG入门指导——include/exclude中的正则表达式
- EXCLUDE/INCLUDE
- TestNG Priority in Test Cases
- The Default Methods And Static Methods In Java Interface
- initialization and destroy methods in bean
- differences between Require, Load, Include and Extend methods
- include-filter和exclude-filter
- jenkins+maven+testng时,报:[TestNGClassFinder] Warning: Can't link and determine methods of class
- OOP in JS, Part 1 : Public/Private Variables and Methods
- Advances in Security and Payment Methods for Mobile Commerce
- An Introduction to Programming and Numerical Methods in MATLAB
- Advances in Security and Payment Methods for Mobile Commerce
- Java Methods for Financial Engineering: Applications in Finance and Investment
- Emerging Methods, Technologies and Process Management in Software Engineering
- 模块获取工具
- 正则表达式分组捕获说明
- 经典消费者生产者问题
- ArcGIS API for Javascript3.23加载高德地图
- 解决同一个页面不能跳转的问题
- Include and Exclude Test Methods in TestNG
- 《懒人Shell脚本》之十——统计多重路径下的不同扩展名文件及个数
- os模块有关
- 阿里云总裁胡晓明:AI泡沫过后,下一站是“产业AI”
- Recycleview添加item点击事件
- Unity3D
- ASP 验证码工具类
- Linux查看文件路径
- Java+Selenium3方法篇21-webdriver处理浏览器多窗口切换