这一篇我们主要学习如下几个知识点:

⑴关于testng.xml

⑵创建一个测试套件

⑶执行testng.xml

⑷在测试套件中创建多个测试用例

⑸在用例中增加class,packages, method

⑹用例中包含/不包含class,packages, method

⑺⑻⑼⑽

在开始学习这些知识点之前,需要在eclipse中先创建一个java 项目,结构如下:

在每个class文件中增加如下代码

import org.testng.annotations.Test;

public class FirstTestClass {
@Test
public void firstTest(){
System.out.println("First test method");
}

@Test
public void secondTest(){
System.out.println("Second test method");
}

}

其中方法test.thirdpackage.FirstTestClass.firstTest()的注解修改为 @Test (groups={"test-one"}) 【关注testng的注解在后面的文章中会有解释】

1、class-testng.xml 文件用来展示如何只执行class,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Class Suite" verbose="1">
<test name="Test">
<classes>
<class name="test.firstpackage.FirstTestClass"/>
<class name="test.secondpackage.FirstTestClass"/>
<class name="test.thirdpackage.FirstTestClass"/>

</classes>
</test>
</suite>

2、combine-testng.xml文件用来展示如何执行firstpackage,secondpackage.FirstTestClass,thirdpackage.FirstTestClass.firstTest,内容如下

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Combine Suite" verbose="1">
<test name="Combine Test">
<packages>
<package name="test.firstpackage" />
</packages>
<classes>
<class name="test.secondpackage.FirstTestClass" />
<class name="test.thirdpackage.FirstTestClass" >
<methods>
<include name="firstTest"/>
</methods>
</class>
</classes>
</test>
</suite>

3、exclude-method-testng.xml用来展示如何不包含methods,内容如下;

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Exclude Method Suite" verbose="1">
<test name="Exclude Method Test">
<classes>
<class name="test.firstpackage.FirstTestClass">
<methods>
<exclude name="firstTest" />
</methods>
</class>
</classes>
</test>
</suite>

4、exclude-package-testng.xml用例展示如何不执行某个packages,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Exclude Method Suite" verbose="1">
<test name="Exclude Method Test">
<classes>
<class name="test.firstpackage.FirstTestClass">
<methods>
<exclude name="firstTest" />
</methods>
</class>
</classes>
</test>
</suite>

5、include-package-testng.xml用例展示如何只执行packages,内容如下:

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Include Package Suite" verbose="1">
<test name="Include Package Test">
<packages>
<package name="test.*">
<include name="test.secondpackage"/>
</package>
</packages>
</test>
</suite>

6、method-testng.xml用例展示如何只执行某个方法

<?xml version="1.0" encoding="UTF-8"?>
<suite name="Method Suite" verbose="1">
<test name="Method Test">
<classes>
<class name="test.firstpackage.FirstTestClass">
<methods>
<include name="firstTest"/>
</methods>
</class> 
<!--  <class name="test.thirdpackage.FirstTestClass"/> -->

</classes>
</test>
</suite>

7、group-testng.xml 展示了如何执行某个组中的用例

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Group Suite" verbose="1">
<test name="Group Test">
<groups>
<run>
<include name="test-one" />
</run>
</groups>
<classes>
<class name="test.thirdpackage.FirstTestClass" />
</classes>
</test>
</suite>

准备好之后,右击xml文件,【Run As】——【TestNG Suite】然后在 eclipse底部的【Result of running suite】中查看每个xml执行的结果吧

TestNG 入门指导——理解testng.xml执行/不执行某个包,某个类,某个方法的更多相关文章

  1. 执行引入外部 jar 包的类的方法

    liunx 系统中,命令行中语法:(.后面是冒号:) java -cp .:third.jar MyClass windows 系统中命令行的语法:(.后面是分号;) java -cp .;third ...

  2. testng入门教程12 TestNG执行多线程测试

    testng入门教程 TestNG执行多线程测试 testng入门教程 TestNG执行多线程测试 并行(多线程)技术在软件术语里被定义为软件.操作系统或者程序可以并行地执行另外一段程序中多个部分或者 ...

  3. testng入门教程10 TestNG参数化测试

    在TestNG的另一个有趣的功能是参数测试.在大多数情况下,你会遇到这样一个场景,业务逻辑需要一个巨大的不同数量的测试.参数测试,允许开发人员运行同样的测试,一遍又一遍使用不同的值. TestNG让你 ...

  4. testng入门教程9 TestNG依赖测试

    有时候,你可能需要在一个特定的顺序调用方法在测试案例,或你想分享一些数据和方法之间的状态.TestNG支持这种依赖测试方法之间的显式依赖它支持声明. TestNG允许指定依赖,无论与否: 使用属性de ...

  5. testng入门教程8 TestNG异常测试

    TestNG跟踪异常处理代码提供了一个选项.可以测试是否需要代码抛出异常或不抛出. @Test注释expectedExceptions 参数一起使用.现在,让我们来看看@Test(expectedEx ...

  6. testng入门教程7 TestNG组测试

    在TestNG中组测试是一个新的创新功能,它不存在于JUnit框架,它允许调度到适当的部分方法和瓶坯复杂的测试方法分组.您不仅可以声明属于群体的那些方法,但你也可以指定一组包含其他组.然后,TestN ...

  7. testng入门教程6 TestNG忽略测试

    有时,我们的代码是没有准备好,如果测试用例写入到测试方法/代码将无法运行,在这种情况下,@Test(enabled = false)有助于禁用此测试案例. 测试方法是标注了@Test(enabled ...

  8. testng入门教程11 TestNG运行JUnit测试

    现在,您已经了解了TestNG和它的各种测试,如果现在担心如何重构现有的JUnit代码,那就没有必要,使用TestNG提供了一种方法,从JUnit和TestNG按照自己的节奏.也可以使用TestNG执 ...

  9. jvm入门及理解(三)——运行时数据区(程序计数器+本地方法栈)

    一.内存与线程 内存: 内存是非常重要的系统资源,是硬盘和cpu的中间仓库及桥梁,承载着操作系统和应用程序的实时运行.JVM内存布局规定了JAVA在运行过程中内存申请.分配.管理的策略,保证了JVM的 ...

随机推荐

  1. 用Duplex实现消息广播

    WCF中定义3种消息交换模式: 1. Request/Reply; 2. One-Way; 3. Duplex.  Request/Reply 是缺省模式,即同步调用.在调用服务方法后需要等待服务的消 ...

  2. 四大Java EE容器(Tomcat、JBoss、Resin、Glassfish)之简单比较

    转自:http://www.cxybl.com/html/bcyy/java/201106241007.html 现在流行的Java EE容器有很多:Tomcat.JBoss.Resin.Glassf ...

  3. java.lang.CharSequence cannot be resolved

    转自:http://jingyan.baidu.com/article/f25ef2546eace4482c1b82a9.html 方法/步骤 1 在MyEclipse中的配置方式为:右击项目-> ...

  4. Shell脚本判断内容为None的方式

    1.判断变量 read -p "input a word :" word if [ ! -n "$word" ] ;then echo "you ha ...

  5. [CoreOS 转载] CoreOS实践指南(一)

    转载:http://www.csdn.net/article/2014-12-29/2823356 摘要:CoreOS是一个采用了高度精简的系统内核及外围定制的操作系统.ThoughtWorks的软件 ...

  6. [Windows Azure] Monitoring SQL Database Using Dynamic Management Views

    Monitoring Windows Azure SQL Database Using Dynamic Management Views 5 out of 7 rated this helpful - ...

  7. [Windows Azure] Development Considerations in Windows Azure SQL Database

    Development Considerations in Windows Azure SQL Database 3 out of 5 rated this helpful - Rate this t ...

  8. 每日英语:Three Shows That Changed The Way Networks Think About Viewership

    As we continue examining this season’s DVR success stories in The Blacklist and Sleepy Hollow it mak ...

  9. webpack打包调试react并使用babel编译jsx配置方法

    http://lxj8749.iteye.com/blog/2287074 ********************************************** 安装webpack npm i ...

  10. MSTP故障处理手册

    H3C核心交换机常见故障定位手册.pdf MSTP故障处理手册.pdf 目 录 1 MSTP故障处理 1.1 广播风暴故障处理 1.1.1 故障描述 1.1.2 故障处理流程 1.1.3 故障处理步骤 ...