你可以通过以下几种不同的方法触发TestNG:

  • 用一个testng.xml文件
  • 使用ant
  • 从命令行触发

这个章节将会介绍testng.xml的格式(你也可以在下面找到关于ant和命令行的内容)。

关于testng.xml当前版本的DTD文件可以在这个网站找到:testng-1.0.dtd

这有一个testng.xml文件的示例:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1" >
<test name="Nopackage" >
<classes>
<class name="NoPackageTest" />
</classes>
</test> <test name="Regression1">
<classes>
<class name="test.sample.ParameterSample"/>
<class name="test.sample.ParameterTest"/>
</classes>
</test>
</suite>

你也可以通过设置包名来定义xml文件:

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1" >
<test name="Regression1" >
<packages>
<package name="test.sample" />
</packages>
</test>
</suite>

在这个例子中,TestNG将会在test.sample包中寻找所有的类,然后将含有TestNG注解的类保留下来执行。

你也可以具体包含或者排除某些组和方法:

<test name="Regression1">
<groups>
<run>
<exclude name="brokenTests" />
<include name="checkinTests" />
</run>
</groups> <classes>
<class name="test.IndividualMethodsTest">
<methods>
<include name="testMethod" />
</methods>
</class>
</classes>
</test>

你也可以在一个testng.xml文件中定义一些新的组并添加属性,比如是否并行运行测试,需要多少个线程,是否运行JUnit测试等等。

默认情况下,TestNG将会按照XML中放置的顺序运行测试用例,如果你想以随机的顺序运行文件中的类和方法,需要将preserve-order属性设置为false。

<test name="Regression1" preserve-order="false">
<classes> <class name="test.Test1">
<methods>
<include name="m1" />
<include name="m2" />
</methods>
</class> <class name="test.Test2" /> </classes>
</test>

请通过查询DTD文件来查看完整的特性。

testNG官方文档翻译-3 testng.xml的更多相关文章

  1. testNG官方文档翻译-5 测试方法,测试类和测试组

    5.1 - 测试方法 测试方法是被 @Test注解的方法.这些方法的返回值会被忽略,除非在testng.xml中将allow-return-values设置为true. <suite allow ...

  2. testNG官方文档翻译-2 注解

    这里是一份TestNG中的可用注解及其属性的概述. 一.用于一个TestNG类的信息配置的注解: @BeforeSuite:被BeforeSuite注解的方法将在其所在suite中的所有test运行之 ...

  3. testNG官方文档翻译-1 简介

    官方文档链接http://testng.org/doc/documentation-main.html 简介 TestNG是一个被设计用来简化广泛的测试需求的测试框架,它既可应用于单元测试(测试一个独 ...

  4. testNG官方文档翻译-4 运行TestNG

    TestNG可以通过不同的方法触发运行: 命令行 ant Eclipse IntelliJ's IDEA

  5. 【TestNG测试】TestNG、Maven、testng.xml构建测试工程

    创建一个maven工程 使用Idea创建maven工程 ​ 建立类似如上的工程结构,src/main/java,src/test/java,pom.xml,testng.xml,这里由于我们使用工程是 ...

  6. TestNG(十五)xml文件实现多线程测试

    package com.course.testng.thread; import org.testng.annotations.Test; public class ThreadOnXml { @Te ...

  7. Spring官方文档翻译(1~6章)

    Spring官方文档翻译(1~6章) 转载至 http://blog.csdn.net/tangtong1/article/details/51326887 Spring官方文档.参考中文文档 一.S ...

  8. TestNG简单的学习-TestNG运行

    转载:http://topmanopensource.iteye.com/blog/1983735 TestNG简单的学习-TestNG运行 文档来自官方地址: http://testng.org/d ...

  9. Retrofit官方文档翻译

    Retrofit官方文档翻译 官方文档网址 http://square.github.io/retrofit/ 介绍 Retrofit 将你的 HTTP API 转换为 Java 接口. public ...

随机推荐

  1. asp.net 随笔

    20190625 网站发布后,添加文件,必须重启iis的应用程序池和网站才能使用添加的文件.

  2. Python模块学习之xlrd 读取Excel时传入formatting_info=True报错:NotImplementedError: formatting_info=True not yet implemented

    问题:xlrd读取Excel时传入 formatting_info=True 报错 之前我们使用读取xls文件的时候都是使用的xlrd库,但是这个库只能操作 .xls格式,对于后来的 .xlsx的版本 ...

  3. MySQL高级学习笔记(四):索引优化分析

    文章目录 性能下降 SQL慢 执行时间长 等待时间长 查询语句写的烂 查询数据过多 关联了太多的表,太多join 没有利用到索引 单值 复合 服务器调优及各个参数设置(缓冲.线程数等)(不重要DBA的 ...

  4. AutoMapper用法 转载https://www.cnblogs.com/youring2/p/automapper.html

    AutoMapper是对象到对象的映射工具.在完成映射规则之后,AutoMapper可以将源对象转换为目标对象. 配置AutoMapper映射规则 AutoMapper是基于约定的,因此在实用映射之前 ...

  5. python3_列表排序简介

    说明:以下是以整数排列为例,其它数据类型读者自行思考即可知. 1.使用方法sort()对列表排序 使用格式:(注:说到方法,在列表中都是列表名.方法名()的使用格式,之后不在赘述.) 列表名.sort ...

  6. mac、windows系统charles安装破解

    一.下载 官网下载适合自己电脑的最新版本 下载地址:https://www.charlesproxy.com/latest-release/download.do 二.破解 破解地址:https:// ...

  7. 【react】---react中key值的作用

    一.React中key值得作用 react中的key属性,它是一个特殊的属性,它是出现不是给开发者用的,而是给React自己使用,有了key属性后,就可以与组件建立了一种对应关系,简单说,react利 ...

  8. Cocos2d-x 发布 Android

    Cocos2d-x 发布 Android 前置需求: Android NDK Android SDK OR Eclipse ADT Bundle Android AVD target installe ...

  9. spark性能调优01-常规调优

    1.分配更多的资源 1.1 分配的资源有:executor.cup per executor.memory per executor.driver memory 1.2 如何分配:在spark-sub ...

  10. uoj175 【Goodbye Yiwei】新年的网警

    题目 胡乱分析 不妨定谣言的源头得到谣言的时刻为\(1\),那么其他人听到谣言的时间就是源头到这个点的最短路 假设\(i\)是谣言的源头,那么如果存在一个点\(j\)满足\(\forall k\in[ ...