TestNG关键字和testNG.xml结构学习

时间:2022-09-30 20:31:23

转自官网: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&period;xml的配置和使用,以及参数传递

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

  2. Ant学习-002-ant 执行 TestNG 测试用例时 &lbrack;testng&rsqb; java&period;lang&period;NoClassDefFoundError&colon; com&sol;beust&sol;jcommander&sol;ParameterException 解决方案

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

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

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

  4. maven &plus; appium &plus; testng &plus; java之pom&period;xml

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

  5. Java - Test - TestNG&colon; Idea 引入 testng&period;xml 自动生成插件

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

  6. APP接口自动化测试JAVA&plus;TestNG&lpar;二&rpar;之TestNG简介与基础实例

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

  7. xml基础之二&lpar;XML结构【2】&rpar;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. SharePoint 2013 网站应用程序、网站集、网站知识整理

    网站应用程序:Web 应用程序是一种可以通过Web访问的应用程序.我们自己以前用VS开发的Web应用程序一般是通过人工部署到IIS上的,而SharePoint的Web应用程序是由SharePoint安 ...

  2. &lbrack;Swift&rsqb;LeetCode373&period; 查找和最小的K对数字 &vert; Find K Pairs with Smallest Sums

    You are given two integer arrays nums1 and nums2 sorted in ascending order and an integer k. Define ...

  3. vs2015安装及初步试用

    Vs2015一直都听说好用,便捷.之前用vc++6.0,总感觉界面很灰,让人编程兴趣不高,恰巧借此机会,安装一下vs2015,从编译器上体验下编程的舒心,方便.希望我不会变得太懒... 首先,我下的是 ...

  4. 【逆向工具】使用x64dbg&plus;spy去除WinRAR5&period;40&lpar;64位&rpar;广告弹框

    1 学习目标 WinRAR5.40(64位)的弹框广告去除,由于我的系统为x64版本,所以安装了WinRAR(x64)版本. OD无法调试64位的程序,可以让我熟悉x64dbg进行调试的界面. 其次是 ...

  5. 搭建Hadoop2&period;7&period;1的分布式集群

    Hadoop 2.7.1 (2015-7-6更新),hadoop的环境配置不是特别的复杂,但是确实有很多细节需要注意,不然会造成许多配置错误的情况.尽量保证一次配置正确防止反复修改. 网上教程有很多关 ...

  6. 实习第二天-今年第一场雨-方法的重载(马上想到println&lpar;&rpar;函数和abs(函数))

    在C语言中 调用函数abs()返回一个整数的绝对值, fabs(返回一个单精度浮点型的绝对值)若要返回这些数的绝对值,则必须记住这些函数的名字 java可以用方法的重载:即是方法名必须相同,参数必须不 ...

  7. HDFS命令实现分析

    HDFS命令概述 HDFS命令涉及两类,一类是hadoop命令,一类是hdfs命令,功能也分为两类,第一类是HDFS文件操作命令,第二类是HDFS管理命令. 二者都是shell命令,真正的命令只有ha ...

  8. 在腾讯ubuntu云服务器上面部署asp&period;net core 2&period;1网站

    微软以后的政策肯定是在开源和跨平台这一块,所以最近在学习asp.net core 2.1,查看市面上面大部分的把asp.net core部署在Linux后,决定亲自实验一番,不操作不知道,居然最新版本 ...

  9. 题解 P1420 【最长连号】

    这个题过去的同学可以再来一题(P1567 统计天数): https://www.luogu.org/problemnew/show/P1567 是的,这个题其实也不是很难,就是前后比较,将天数压栈, ...

  10. Python——List

    一.集成开发环境 集成开发环境(IDE,Integrated development Enviroment)是用于提供程序开发环境的应用程序,一般包括代码编辑器.编译器.调试器和图形用户界面等工具.集 ...