转自官网:http://testng.org/doc/documentation-main.html#test-results

TestNG关键字

@BeforeSuite
@AfterSuite
@BeforeTest
@AfterTest
@BeforeGroups
@AfterGroups
@BeforeClass
@AfterClass
@BeforeMethod
@AfterMethod

@BeforeSuite: The annotated method will be run before all tests in this suite have run. 
@AfterSuite: The annotated method will be run after all tests in this suite have run. 
@BeforeTest: The annotated method will be run before any test method belonging

to the classes inside the <test> tag is run. 
@AfterTest: The annotated method will be run after all the test methods belonging

to the classes inside the <test> tag have run. 
@BeforeGroups: The list of groups that this configuration method will run before.

This method is guaranteed to run shortly before the first test method that belongs

to any of these groups is invoked.
@AfterGroups: The list of groups that this configuration method will run after.

This method is guaranteed to run shortly after the last test method that belongs

to any of these groups is invoked. 
@BeforeClass: The annotated method will be run before the first test method in

the current class is invoked. 
@AfterClass: The annotated method will be run after all the test methods in the

current class have been run. 
@BeforeMethod: The annotated method will be run before each test method. 
@AfterMethod: The annotated method will be run after each test method.

testNG.xml结构

The concepts used in this documentation are as follows:

  • A suite is represented by one XML file. It can contain one or more tests and is defined by the <suite> tag.
  • A test is represented by <test> and can contain one or more TestNG classes.
  • A TestNG class is a Java class that contains at least one TestNG annotation. It is represented by the <class> tag and can contain one or more test methods.
  • A test method is a Java method annotated by @Test in your source.

Here is an example testng.xml file:

<!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>
 

You can specify package names instead of class names:

<!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>
 

In this example, TestNG will look at all the classes in the package test.sample and will retain only classes that have TestNG annotations.

You can also specify groups and methods to be included and excluded:

public class Test1 {
@Test(groups = { "functest", "checkintest" })
public void testMethod1() {
} @Test(groups = {"functest", "checkintest"} )
public void testMethod2() {
} @Test(groups = { "functest" })
public void testMethod3() {
}
}
<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>
 

You can also define new groups inside testng.xml and specify additional details in attributes, such as whether to run the tests in parallel, how many threads to use, whether you are running JUnit tests, etc...


By default, TestNG will run your tests in the order they are found in the XML file. If you want the classes and methods listed in this file to be run in an unpredictible order, set the preserve-order attribute to 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>
 

Please see the DTD for a complete list of the features, or read on.

TestNG关键字和testNG.xml结构学习的更多相关文章

  1. testng教程之testng.xml的配置和使用,以及参数传递

    昨天学习了一下testng基础教程,http://www.cnblogs.com/tobecrazy/p/4579414.html 昨天主要学习的是testng 的annotation基本用法和生命周 ...

  2. Ant学习-002-ant 执行 TestNG 测试用例时 [testng] java.lang.NoClassDefFoundError: com/beust/jcommander/ParameterException 解决方案

    上篇文章中概述了 Ant windows 环境的基本配置,此文讲述在初次使用的过程中遇到的问题. 今天通过 ant 执行 TestNG 测试用例时,执行报错,相应的错误信息如下所示: Buildfil ...

  3. IDEA 单元测试testng入门及testng.xml

    直接进入正题: 1.TestNG的运行方式如下: With a testng.xml file 直接run as test suite With ant 使用ant From the command ...

  4. maven + appium + testng + java之pom.xml

    参考来源:<https://search.maven.org/remotecontent?filepath=io/appium/java-client/3.3.0/java-client-3.3 ...

  5. Java - Test - TestNG: Idea 引入 testng.xml 自动生成插件

    1. 概述 Idea 引入自动生成 testng.xml 插件 自动生成 testng.xml 2. 背景 testng 调试 调试 testng, 主要是这两种方法 ide 下直接执行测试 方法 类 ...

  6. APP接口自动化测试JAVA+TestNG(二)之TestNG简介与基础实例

    前言 继上篇环境篇后,本篇主要对TestNG进行介绍,给出最最基础的两个实例,通过本文后,学会并掌握TestNG测试用例的编写与运行,以及生成美化后的报告.下一篇为HTTP接口实战(国家气象局接口自动 ...

  7. xml基础之二(XML结构【2】)DTD文档模版

    xml基础之二(XML结构[2])DTD文档模版 xml 模板 文档结构  我们知道XML主要用于数据的存储和传输,所以无论是自定义还是外部引用DTD模板文档,都是为了突出数据的存储规范.DTD(文档 ...

  8. XML基础学习01

    XML学习 1:XML:可扩展的标识语言,是一种描述结构数据的格式,简化了网络中数据交换和表示,使得代码,数据和表示分离,并作为数据交换的标准格式,被称为智能数据文档. 2:当我们不使用数据库来存储数 ...

  9. xml基础学习笔记05

    Xpath快速解析 如题一样,本篇主要说说Xpath快速查找XML文档   * Xpatn.Xquery,是专门用来查询xml的语言   * 查询xml非常快   Xpatn.Xquery,是专门用来 ...

随机推荐

  1. PDF在线预览

    1.所需插件jquery.media.js或者pdfobject.js 代码: <html> <head> <style type="text/css" ...

  2. express 安装与卸载

    卸载: npm uninstall -g express安装指定版本: npm install -g express@3.5.0查看版本: express -V注意express -V中的V要大写,不 ...

  3. hadoop 分片与分块,map task和reduce task的理解

    分块:Block HDFS存储系统中,引入了文件系统的分块概念(block),块是存储的最小单位,HDFS定义其大小为64MB.与单磁盘文件系统相似,存储在 HDFS上的文件均存储为多个块,不同的是, ...

  4. elastic search 学习笔记

    Elastic search在数据分析的应用中相当于一个数据库的搜索引擎. 跟MySQL类似,它有自己的查询语言,只不过不是关系型数据库,属于NoSQL. 可以根据索引从分布式服务器文件系统中快速存取 ...

  5. pthread_setcanceltype 线程取消

    取消线程: (1)一个线程可以调用pthread_cancel来取消另一个线程.    (2)被取消的线程需要被join来释放资源.    (3)被取消的线程的返回值为PTHREAD_CANCELED ...

  6. Problem:To Connect with MySQL in Virtual PC Environment

    I'm trying to build a 1:n dev environment,with the help of Vsever(just like VMware worked on sever) ...

  7. hadoop 生态系统版本对应问题

    http://hbase.apache.org/book.html 这是hortonworks的哦哦哦哦哦哦哦哦哦哦哦哦 Hadoop 2.x is better than Hadoop 1.x Ha ...

  8. tail tailf 使用

    tail -f tailf 用来查看日志的新增内容, tailf 能一直打印日志

  9. 巧用powerpoint制作符合期刊要求的复合图

  10. Maximum Submatrix 2

    Codeforces Round #221 (Div. 1) B:http://codeforces.com/problemset/problem/375/B 题意:给你一个n*m的0,1矩阵,你可以 ...