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

⑴关于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. Atitit tomcat在linux服务器的启动与其他

    Atitit tomcat在linux服务器的启动与其他 1.1. /home/tomcat/tomcat3/bin/startup.sh1 1.2. 判断启动是否成功 ps -ef|grep tom ...

  2. 【Objective-C】OC中KVO的基本概念和使用方法

    基本概念: 键值观察是一种使用获取其他对象的特定属性变化的通知机制. 控制器层的绑定技术就是严重依赖键值观察获得模型层和控制器层的变化通知的. 对于不依赖控制器层类的应用程序,键值观察提供了一种简化的 ...

  3. vue-webpack快速建立项目模板

  4. nginx 404 403等错误信息页面重定向到网站首页或其它事先指定的页面

    server { listen 80; server_name www.espressos.cn; location / { root html/www; index index.html index ...

  5. [Windows Azure] Using the Graph API to Query Windows Azure AD

    Using the Graph API to Query Windows Azure AD 4 out of 4 rated this helpful - Rate this topic This d ...

  6. kindeditor自定义插件插入视频代码

    kindeditor自定义插件插入视频代码 1.添加插件js 目录:/kindeditor/plugins/diy_video/diy_video.js KindEditor.plugin('diy_ ...

  7. ss安装

    安装很简单,如下: apt-get install python-pip pip install shadowsocks 配置文件格式如下: { "server":"0. ...

  8. LOCAL_EXPORT_C_INCLUDES和LOCALC_INCLUDES 的差别

    http://stackoverflow.com/questions/6595208/what-does-this-line-mean-local-export-c-includes LOCAL_EX ...

  9. SPSS简单使用

    当我们的调查问卷在把调查数据拿回来后,我们该做的工作就是用相关的统计软件进行处理,在此,我们以spss为处理软件,来简要说明一下问卷的处理过程,它的过程大致可分为四个过程:定义变量.数据录入.统计分析 ...

  10. linux跑火车的命令sl

    http://forum.ubuntu.org.cn/viewtopic.php?t=250890 ubuntu下可以通过 apt-get install sl 安装.执行sl会出来什么呢?帖一下: ...