TestNG – Run multiple test classes (suite test)
In this tutorial, we will show you how to run multiple TestNG test cases (classes) together, aka suite test.
1. Test Classes
Review following three test classes.
package com.mkyong.testng.examples.suite;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
//show the use of @BeforeSuite and @BeforeTest
public class TestConfig {
@BeforeSuite
public void testBeforeSuite() {
System.out.println("testBeforeSuite()");
}
@AfterSuite
public void testAfterSuite() {
System.out.println("testAfterSuite()");
}
@BeforeTest
public void testBeforeTest() {
System.out.println("testBeforeTest()");
}
@AfterTest
public void testAfterTest() {
System.out.println("testAfterTest()");
}
}
package com.mkyong.testng.examples.suite;
import org.testng.annotations.Test;
public class TestDatabase {
@Test(groups = "db")
public void testConnectOracle() {
System.out.println("testConnectOracle()");
}
@Test(groups = "db")
public void testConnectMsSQL() {
System.out.println("testConnectMsSQL");
}
@Test(groups = "db-nosql")
public void testConnectMongoDB() {
System.out.println("testConnectMongoDB");
}
@Test(groups = { "db", "brokenTests" })
public void testConnectMySQL() {
System.out.println("testConnectMySQL");
}
}
package com.mkyong.testng.examples.suite;
import org.testng.annotations.Test;
public class TestOrder {
@Test(groups={"orderBo", "save"})
public void testMakeOrder() {
System.out.println("testMakeOrder");
}
@Test(groups={"orderBo", "save"})
public void testMakeEmptyOrder() {
System.out.println("testMakeEmptyOrder");
}
@Test(groups="orderBo")
public void testUpdateOrder() {
System.out.println("testUpdateOrder");
}
@Test(groups="orderBo")
public void testFindOrder() {
System.out.println("testFindOrder");
}
}
2. Testng.xml
To run above test classes, create a XML file – testng.xml
(can be any filename) file, and define detail like this :
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
<test name="order">
<classes>
<class name="com.mkyong.testng.examples.suite.TestConfig" />
<class name="com.mkyong.testng.examples.suite.TestOrder" />
</classes>
</test>
<test name="database">
<classes>
<class name="com.mkyong.testng.examples.suite.TestConfig" />
<class name="com.mkyong.testng.examples.suite.TestDatabase" />
</classes>
</test>
</suite>
Output
[TestNG] Running:
C:\mkyong_projects\TestNG\src\test\resources\testng-all.xml
testBeforeSuite()
testBeforeTest()
testFindOrder
testMakeEmptyOrder
testMakeOrder
testUpdateOrder
testAfterTest()
testBeforeTest()
testConnectMongoDB
testConnectMsSQL
testConnectMySQL
testConnectOracle()
testAfterTest()
testAfterSuite()
3. Other Examples
Here are some common use examples.
3.1 Specify package names instead of class names:
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
<test name="order">
<packages>
<package name="com.mkyong.testng.examples.suite.*" />
</packages>
</test>
</suite>
3.2 Specify methods to include or exclude :
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
<test name="order">
<classes>
<class name="com.mkyong.testng.examples.suite.TestConfig" />
<class name="com.mkyong.testng.examples.suite.TestOrder">
<methods>
<include name="testMakeOrder" />
<include name="testUpdateOrder" />
<!--
<exclude name="testMakeOrder" />
-->
</methods>
</class>
</classes>
</test>
</suite>
Output
[TestNG] Running:
C:\mkyong_projects\TestNG\src\test\resources\testng.xml
testBeforeSuite()
testBeforeTest()
testMakeOrder
testUpdateOrder
testAfterTest()
testAfterSuite()
3.3 Specify groups to include or exclude :
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="TestAll">
<test name="database">
<groups>
<run>
<exclude name="brokenTests" />
<include name="db" />
</run>
</groups>
<classes>
<class name="com.mkyong.testng.examples.suite.TestDatabase" />
</classes>
</test>
</suite>
Output
[TestNG] Running:
C:\mkyong_projects\TestNG\src\test\resources\testng.xml
testConnectMsSQL
testConnectOracle()
According to the TestNG dtd, the exclude
element is only applicable to the following elements:
- package - The package description within packages list.
- methods - The list of methods to include/exclude from this test.
- run - The subtag of groups used to define which groups should be run.
The elements cl***
and class
cannot be directly excluded; however, you can exclude cl*** through groups:
@Test(groups = { "ClassTest1" })
public class Test1 {
public void testMethod1() {
}
public void testMethod2() {
}
}
Then you will define the testng.xml:
<suite>
<test>
<groups>
<run>
<exclude name="ClassTest1"/>
</run>
</groups>
<cl***>
<class name="Test1">
</cl***>
</test>
</suite>
TestNG – Run multiple test classes (suite test)的更多相关文章
- PHPFarm - How to run multiple versions of PHP on the same computer
How to Run Multiple Versions of PHP on One Server 转载:http://www.sitepoint.com/run-multiple-versions- ...
- 【转帖】如何在redhat单机服务器上运行postgresql的多个实例(howto run multiple postgresql instance on one redhat server)
Running multiple PostgreSQL 9.2 Instances on one server in CentOS 6/RHEL 6/Fedora 原帖网站速度很慢,故转帖在此 Thi ...
- Run Multiple Webpack Configs Sequentially
https://www.viget.com/articles/run-multiple-webpack-configs-sequentially/ const path = require('path ...
- Spark机器学习· 实时机器学习
Spark机器学习 1 在线学习 模型随着接收的新消息,不断更新自己:而不是像离线训练一次次重新训练. 2 Spark Streaming 离散化流(DStream) 输入源:Akka actors. ...
- Spark机器学习9· 实时机器学习(scala with sbt)
1 在线学习 模型随着接收的新消息,不断更新自己:而不是像离线训练一次次重新训练. 2 Spark Streaming 离散化流(DStream) 输入源:Akka actors.消息队列.Flume ...
- ExtentReports 结合 TestNg 生成自动化 html 报告 (支持多 suite)
转载:https://testerhome.com/topics/8134 重要说明:报告监听器源码修复一些bug,不再此处更新代码,最新代码可以到github查看最新报告监听器源码 前几天分享了ht ...
- testng 执行多个suite
我们知道testng的配置文件,一个.xml里面只能有一个suite,那么如果想要设置多个suite怎么弄呢?这个时候我们需要用到testng的标签<suite-files>. 下面说一下 ...
- testng执行多个suite
由于testng.xml中只能设置一个<suite>标签,就无法创建多个测试集,通过<suite-files >标签可以实现允许多个测试集. 1.testng.xml中引入多个 ...
- TestNG Suite 运行出现中文乱码如何解决
场景: 用TestNG框架运行测试类,控制台视图输出出现中文乱码. 解决方案: 1.eclipse属性>workspace>other>utf-8 2.修改eclipse.ini 文 ...
随机推荐
- hdu2022
#include <stdio.h> #include <math.h> #define here puts("go,go,go!\n") int main ...
- .NET重构(五):存储过程、触发器和函数的区别
导读:在触发器的学习过程中,师傅讲了它的耦合性高,建议我能用存储过程,那到底什么是存储过程呢,自己也不是特别了解,还有就是,触发器也算是一种特殊的存储过程,为什么就不建议多用呢?接下来,就谈谈触发器. ...
- Selenium WebDriver高级用法
Selenium GitHub地址 选择合适的WebDrvier WebDriver是一个接口,它有几种实现,分别是HtmlUnitDrvier.FirefoxDriver.InternetExplo ...
- hdu6059[字典树+思维] 2017多校3
#include <bits/stdc++.h> using namespace std; typedef long long LL; * ][]; * ]; * ]; ][]; ; LL ...
- [图论训练]BZOJ 1624: [Usaco2008 Open] Clear And Present Danger 寻宝之路【floyd】
Description 农夫约翰正驾驶一条小艇在牛勒比海上航行. 海上有N(1≤N≤100)个岛屿,用1到N编号.约翰从1号小岛出发,最后到达N号小岛.一 张藏宝图上说,如果他的路程上 ...
- java面试题之sleep()和wait()方法的区别
sleep方法: 属于Thread类中的方法:会导致程序暂停执行指定的时间,让出cpu该其他线程,但是他的监控状态依然保持着,当指定时间到了之后,又会自动恢复运行状态:在调用sleep方法的过程中,线 ...
- C++ string 类中的 assign()函数
C++ string 类的成员函数,用于拷贝.赋值操作,它们允许我们顺次地把一个 string 对象的部分内容拷贝到另一个 string 对象上. 函数原型 string &operator= ...
- CSS选择器与XPath语言
一 在爬取页面信息的过程中,需要到想要的信息进行定位,主要有两种方法.CSS选择器和XPath语言.查找某一个标签,两种方法都可以做到. 二 CSS选择器 http://www.w3school.co ...
- 栅格网络流(cogs 750)
[问题描述] Bob 觉得一般图的最大流问题太难了,他不知道如何解决,于是他想尝试一个简单点的:栅格网络中的最大流问题,这个虽说简单了一点,但对 Bob 来说依旧太难,现在他有个麻烦需要你帮忙:给你一 ...
- ElasticSearch集群状态查看命令大全
Elasticsearch中信息很多,同时ES也有很多信息查看命令,可以帮助开发者快速查询Elasticsearch的相关信息. _cat $ curl localhost:9200/_cat =^. ...