testng 组

TestNG Groups is one of its very important and useful features. We can specify groups for TestNG methods, it can be used with @Before, @After and @Test methods.

TestNG Groups是其非常重要和有用的功能之一。 我们可以为TestNG方法指定组,它可以与@ Before,@ After和@Test方法一起使用。

TestNG组 (TestNG Groups)

Once we have defined the groups for TestNG methods, we can run specific groups. We can include groups to be executed, exclude groups. We can also create a group of groups. Let’s create a TestNG test class with few methods and assign them to different groups.

一旦为TestNG方法定义了组,就可以运行特定的组。 我们可以包括要执行的组,不包括组。 我们还可以创建一组组。 让我们用很少的方法创建一个TestNG测试类,并将它们分配给不同的组。

package com.journaldev.groups;import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;public class TestNGGroupsExample {@Test(groups = "foo")public void foo() {System.out.println("foo");}@Test(groups = "bar")public void bar() {System.out.println("bar");}@Test(groups = { "alpha", "sanity" })public void alpha() {System.out.println("alpha");}@Test(groups = { "beta", "integration" })public void beta() {System.out.println("beta");}@BeforeClass(groups = "integration")public void beforeIntegrationTests() {System.out.println("Before Running integration test methods");}@AfterClass(groups = "integration")public void afterIntegrationTests() {System.out.println("Before Running integration test methods");}}

使用Eclipse TestNG运行配置运行TestNG组 (Running TestNG Groups using Eclipse TestNG Run Configuration)

When we execute a TestNG class in Eclipse, it executes all the groups. We can create a Run Configuration for specific groups to execute. Go to Run | Run Configurations.

当我们在Eclipse中执行TestNG类时,它将执行所有组。 我们可以为特定的组创建一个运行配置以执行。 去运行| 运行配置

Browse for your project, then select the Groups checkbox and click on Browse button. It will show you all the groups defined in the project.

浏览您的项目,然后选择“组”复选框,然后单击“浏览”按钮。 它将向您显示项目中定义的所有组。

Select the groups to execute and you should see configuration like below image.

选择要执行的组,您将看到下图所示的配置。

Click on “Apply” button to save the configuration. Click on “Run” button to run the configuration, which will execute only the specified groups.

单击“应用”按钮以保存配置。 单击“运行”按钮运行配置,它将仅执行指定的组。

You should get following output in the Eclipse console.

您应该在Eclipse控制台中获得以下输出。

[RemoteTestNG] detected TestNG version 6.14.3
bar
foo
PASSED: bar
PASSED: foo===============================================GRP-bar,fooTests run: 2, Failures: 0, Skips: 0
==============================================================================================
TestNG-Examples by groups
Total tests run: 2, Failures: 0, Skips: 0
===============================================

TestNG XML Suite组示例 (TestNG XML Suite Groups Example)

We can configure our test suite to run specific groups using groups element. Below TestNG XML suite will run only foo and bar group methods.

我们可以配置测试套件以使用groups元素运行特定的组。 在TestNG XML套件下面,将仅运行foobar组方法。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TestNGXMLTest Test Suite"><groups><run><include name="foo"></include><include name="bar"></include></run></groups><test name="TestNGXMLTest Test"><classes><class name="com.journaldev.groups.TestNGGroupsExample" /></classes></test>
</suite>

TestNG XML包含排除组示例 (TestNG XML Include Exclude Groups Example)

Sometimes our methods will be part of multiple groups. If the method is part of both included and excluded groups, then it will be excluded from execution.

有时,我们的方法将成为多个组的一部分。 如果该方法是包含组和排除组的一部分,则将其从执行中排除。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TestNGXMLTest Test Suite"><groups><run><include name="alpha"></include><include name="beta"></include><exclude name="integration"></exclude></run></groups><test name="TestNGXMLTest Test"><classes><class name="com.journaldev.groups.TestNGGroupsExample" /></classes></test>
</suite>

Above test suite will not execute beta() method because one of its groups is in excluded groups list.

上面的测试套件将不会执行beta()方法,因为其组之一在排除组列表中。

TestNG组正则表达式 (TestNG Groups Regular Expression)

TestNG groups configuration supports regular expression. If we change groups include to include name=".*o.*", then it will only execute foo() and beta() methods. It’s because they belong to the groups whose name conatins letter “o”.

TestNG组配置支持正则表达式。 如果我们将包括的组更改为include name=".*o.*" ,则它将仅执行foo()和beta()方法。 这是因为它们属于名称包含字母“ o”的组。

TestNG默认组 (TestNG Default Group)

If we want all our Test class methods to be part of a specific group, we can configure it at the class level.

如果我们希望所有Test类方法都属于特定组,则可以在类级别对其进行配置。

@Test(groups="default")
public class TestNGGroupsExample {
// test methods
}

TestNG组组 (TestNG Group of Groups)

We can define group of groups in the TestNG XML file. Then we can use it in the test suite. Note that this can be done inside only at test level, not at suite level.

我们可以在TestNG XML文件中定义组组。 然后,我们可以在测试套件中使用它。 请注意,只能在测试级别而不是套件级别内部进行此操作。

Let’s look at a quick example of defining groups in the TestNG XML file and then using them.

让我们看一个在TestNG XML文件中定义组然后使用它们的快速示例。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="TestNGXMLTest Test Suite"><test name="TestNGXMLTest Test"><groups><define name="include-groups"><include name="sanity" /><include name="integration" /></define><define name="exclude-groups"><include name="foo" /><include name="bar" /></define><run><include name="include-groups" /><exclude name="exclude-groups" /></run></groups><classes><class name="com.journaldev.groups.TestNGGroupsExample" /></classes></test>
</suite>

That’s all for TestNG groups example. They are very helpful in categorizing our tests and run them for different levels of verification.

这就是TestNG组示例的全部内容。 它们对我们的测试进行分类并为不同级别的验证运行它们非常有帮助。

GitHub Repository.GitHub Repository下载示例代码。

翻译自: https://www.journaldev.com/21349/testng-groups

testng 组

testng 组_TestNG组相关推荐

  1. R语言使用aov函数进行单因素协方差分析(One-way ANCOVA)、使用multcomp包的glht函数检验组均值之间所有成对对比差异、通过contrast参数自定义对比组进行组间两两方差分析

    R语言使用aov函数进行单因素协方差分析(One-way ANCOVA).使用multcomp包的glht函数检验组均值之间所有成对对比差异.通过contrast参数自定义对比组进行组间两两方差分析( ...

  2. linux-组管理-添加组-删除组

    创建组 groupadd 组名 >创建用户组 >查看添加的组信息 添加了组后,组的信息在 /etc/group目录下 查看组帮助 groupadd --help 创建一个组同时指定id g ...

  3. iOS自定义组与组之间的距离以及视图

    iOS自定义组与组之间的距离以及视图 //头视图高度 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(N ...

  4. iOS之UITableView组头组尾视图/标题悬停

    最近笔者在公司的iOS开发中,有一个iOS开发同事跑来问了两个问题:1.给UITableView设置了组头和组尾视图,但是一直显示不出来?2.UITableView的section的header和fo ...

  5. iOS 设置tableview组头组尾的背景色

    直接设置UITableViewHeaderFooterView的backgroundView.backgroundColor或者的backgroundColor,都是没有用的,马克一下设置的table ...

  6. 区号组号组内块号块内地址号的计算

    容量为64块的Cache采用组相联方式映像,字块大小为128个字,每4块为一组.若主存容量为4096块,且以字编址,那么主存地址应为_(?)_位,主存区号应为_(?)_位. 主存地址=区号+组号+组内 ...

  7. 计算机策略组 网络,组策略

    基本信息 中文名 组策略 外文名 Group Policy作    用 设置各种软件.计算机和用户策略 领    域 主要应用于 组策略操作 编辑 语音 组策略在部分意义上是控制用户可以或不能在计算机 ...

  8. 【音乐理论】音与音高 ( 音区 | 小字一组 | 小字组 | 大字组 )

    文章目录 一.音区 二.小字一组 三.小字二组 四.小字三组 五.小字四组 六.小字五组 六.小字组 七.大字组 八.大字一组 九.大字二组 十.音区总结 一.音区 钢琴有 888888 键 , 88 ...

  9. 微生物组+代谢组联合分析

    微生物代谢组学联合分析简介 在肠道中,微生物与宿主之间进行密切的信息交流,在代谢.免疫.神经系统调控中起重要作用.不同组成的微生物能影响机体体重.消化功能.抵御感染和自身免疫疾病的患病风险,此外,还能 ...

最新文章

  1. 从课堂走向实践还有多远?
  2. 微软技术能力测试工具V0.1试用
  3. [1-2] Dependence-Aware Service Function Chain Design and Mapping
  4. 页面未加载完时报的错误
  5. 还在发愁linux命令记不住吗?神器来了!
  6. 连接查询_左连接/右连接/全连接的区别
  7. 用Word2007查找和替换功能批量设置图片位置
  8. mysql不能插入中文
  9. springboot+dubbo
  10. css 设置表格右边有图片_我写CSS常用的方法
  11. go语言报错:main redeclared in this block
  12. node -v 突然显示 killed 9 处理历程
  13. 接口接收数据_你知道RS232与RS485接口的区别吗?
  14. 信息系统项目管理师论文范例4-进度管理
  15. windows/linux多系统并存体验
  16. JPG图像太大怎么免费压缩
  17. ASCII码值是怎么计算的,怎么计算arccos的值
  18. android音频驱动工程师,4.Android音频驱动(底层1)
  19. 自成一派的风格楷体字体
  20. 程鑫峰:1.19伦敦金陷多空交织,长江金业后市行情解析

热门文章

  1. C#参考:Linq 概述
  2. 判断回文(0315)SWUST-OJ
  3. [转载] python四种列表的插入方法及其效率
  4. [转载] 使用Keras和TensorFlow 2.0建立深度学习模型对图像进行分类
  5. [转载] python函数——字典设置默认值get() 与 setdefault()区别
  6. [转载] Python字符串isdecimal() isdigit()isnumeric()等判断方法的区分。
  7. [转载] pandas将Series变成键值对
  8. appium学习【三】:截图时,图片命令中包含当前的函数名,以区分错误是在哪个函数报的...
  9. Python正则表达式:最短匹配
  10. _视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear等的区别及用途...