testng

TestNG annotations helps us in quickly writing test cases, configure them programmatically. Let’s have a look at the most important TestNG annotations.

TestNG批注可帮助我们快速编写测试用例,并以编程方式对其进行配置。 让我们看一下最重要的TestNG批注。

TestNG注释-配置 (TestNG Annotations – Configuration)

TestNG provides following annotations for configuring our test suite and test cases.

TestNG提供以下注释,用于配置我们的测试套件和测试用例。

  1. @BeforeSuite: The method annotated will be executed before any test methods are executed.@BeforeSuite :注释的方法将在执行任何测试方法之前执行。
  2. @AfterSuite: The annotated method will be run after all tests in this suite have run.@AfterSuite :带注释的方法将在该套件中的所有测试运行之后运行。
  3. @BeforeTest: The annotated method will be executed before any test classes in the suite is executed. It’s useful when we have a TestNG XML file, this method will run before any classes in test element.@BeforeTest :带注释的方法将在执行套件中的任何测试类之前执行。 当我们有一个TestNG XML文件时,此方法很有用,此方法将在test元素中的任何类之前运行。
  4. @AfterTest: The annotated method will be executed after all test classes in the suite is executed. It’s useful when we have a TestNG XML file, this method will run after all classes in test element.@AfterTest :带注释的方法将在执行套件中的所有测试类之后执行。 当我们有一个TestNG XML文件时,这很有用,该方法将在test元素中的所有类之后运行。
  5. @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.@BeforeGroups :此配置方法将在其之前运行的组的列表。 保证此方法可以在调用属于这些组中的任何一个的第一个测试方法之前不久运行。
  6. @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.@AfterGroups :此配置方法将在其后运行的组的列表。 保证在调用属于这些组中任何一个的最后一个测试方法后不久便可以运行该方法。
  7. @BeforeClass: The annotated method will be run before the first test method in the current class is invoked.@BeforeClass :带注释的方法将在调用当前类中的第一个测试方法之前运行。
  8. @AfterClass: The annotated method will be run after all the test methods in the current class have been run.@AfterClass :带注释的方法将在当前类中的所有测试方法都运行之后运行。
  9. @BeforeMethod: The annotated method will be run before each test method.@BeforeMethod :带注释的方法将在每个测试方法之前运行。
  10. @AfterMethod: The annotated method will be run after each test method.@AfterMethod :带注释的方法将在每个测试方法之后运行。

TestNG最重要的注释 (TestNG Most Important Annotations)

Let’s look at the TestNG annotations that are mostly used and make it a powerful testing framework.

让我们看一下最常用的TestNG批注,使其成为一个功能强大的测试框架。

  1. @Test: The most important annotation that marks a class or method as part of the test. You can get more details about it at TestNG Tutorial.@Test :最重要的注释,用于将类或方法标记为测试的一部分。 您可以在TestNG Tutorial中获得有关它的更多详细信息。
  2. @DataProvider: This annotation marks a method as input data supplier for a test method. The annotated method must return an Object array that can be assigned as the parameters of the test method. The @Test method defines the data provider method name for supplying input data. You can read more about it at TestNG DataProvider.@DataProvider :此注释将方法标记为测试方法的输入数据提供者。 带注释的方法必须返回一个Object数组,该数组可以分配为测试方法的参数。 @Test方法定义用于提供输入数据的数据提供者方法名称。 您可以在TestNG DataProvider上阅读有关它的更多信息。
  3. @Factory: This annotation is used to mark a method as a factory that returns objects to be used by TestNG as Test classes. The method must return Object[]. Read more at TestNG Factory.@Factory :此批注用于将方法标记为工厂,该方法返回TestNG用作测试类的对象。 该方法必须返回Object []。 在TestNG Factory了解更多。
  4. @Listeners: This annotation is used to define listeners on a test class. It’s a very powerful feature of TestNG framework, read more at TestNG Listeners.@Listeners :此批注用于定义测试类上的侦听器。 这是TestNG框架的一项非常强大的功能,更多内容请参见TestNG Listeners 。
  5. @Parameters: This annotation is used with TestNG XML suite to define the parameter name to be used from XML file for test method input arguments. You can read more about it at TestNG Parameters.@Parameters :此批注与TestNG XML套件一起使用,以定义要从XML文件用于测试方法输入参数的参数名称。 您可以在TestNG Parameters上阅读有关它的更多信息。

That’s all for a quick roundup on TestNG annotations.

这就是对TestNG注释进行快速汇总的全部。

GitHub Repository.GitHub Repository上查看TestNG批注示例。

Reference: TestNG Official Docs

参考: TestNG官方文档

翻译自: https://www.journaldev.com/21399/testng-annotations

testng

testng_TestNG注释相关推荐

  1. testng_TestNG @工厂注释

    testng TestNG @Factory annotation is used to specify a method as a factory for providing objects to ...

  2. Idea groovy表生成实体类带注释

    Idea groovy表生成实体类带注释 1.点开datasourse,打开idea带的数据库工具,具体添加数据库连接,这里不描述. 这时点击会生成一个poji 这时生成的pojo中是不带中文注释的, ...

  3. 快速删除c/c++语言中的注释

    前言 在日常工作中,我们会给c/c++代码写上一些注释,但是往往为了保持最终的代码尽可能小,我们需要删除注释,手动删除太缓慢了,所以我们考虑一下自动删除注释功能 代码 // // Created by ...

  4. linux 文件查找与文件中注释去除

    文件查找 / 查找的文件夹名(/ 从根下查找) find / -name filename 文件中的注释去除 示例文件 使用grep -v "^#" 来去掉注释行,其中:-v 就是 ...

  5. 【VS实践】如何在vs中自动添加注释

    前言: 之前看别人博客关于在vs中添加类注释的,今天自己看到牛腩里的讲述,也就跟着试了试,牛腩有点out了,跟着他的视频,自己还给建错了,找了找原因,也意外的开辟了新大陆! 步骤: 1. 我的vs是2 ...

  6. 基于PyTorch的Seq2Seq翻译模型详细注释介绍(一)

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/qysh123/article/deta ...

  7. Python 函数参数有冒号 声明后有- 箭头 返回值注释 参数类型注释

    在python3.7 环境下 函数声明时能在参数后加冒号,如图: 1 def f(ham: str, eggs: str = 'eggs') -> str : 2 print("Ann ...

  8. Qt实现 指针式时钟+动态时钟 (详细注释)

    先上效果图: 点击运行后首先是一个指针式时钟窗口,点击Digital Clock->可以跳转到数字时钟窗口,再点击Move Clock->可以还原为指针式时钟窗口 关于整个程序的讲解都在代 ...

  9. VsCode允许JSON文件注释

    打开设置面板 输入Files: Associations搜索出此项 在此处添加项: 项 *.json 值 jsonc 然后你的JSON文件注释就不报错了~

最新文章

  1. java 中启动线程的正确方式
  2. Angular 依赖注入
  3. python的模块、包、库区别。导入包/模块的方式
  4. 蓝桥杯java第七届决赛第一题--愤怒小鸟
  5. 田志刚:致《你的知识需要管理》读者
  6. java异常什么时候抛出异常,java - 什么时候应该抛出IllegalArgumentException?
  7. 《Spring揭秘》——IOC梳理2(容器启动,bean生命周期)
  8. Tomcat 配置文件
  9. mybatis中获取当前时间_Mybatis获取当前数据库时间
  10. java多线程-慎重使用volatile关键字
  11. sqlserver中获取一张表中列的数据
  12. 【跟踪算法】MOSSE论文翻译
  13. 什么是serialVersionUID?serialVersionUID详解
  14. SQL Server如何备份数据库?完整数据库备份方式
  15. 5G注册流程分级详解
  16. 土包子也来爆料一下贵族的生活:高尔夫球场见闻
  17. idea中文件被Mark as Plain Text后恢复
  18. 假证假章猖狂不止 公章伪造的沉疴爱签电子印章来治愈
  19. 计算机二级PS教学视频百度云,计算机二级ps考试题库完整教程文件.pdf
  20. 英文年月日(日期)怎么读?

热门文章

  1. [转载] python3.6版本生成的python脚本如何打包为可独立执行的exe程序
  2. [转载] Java静态代码块/构造代码块/构造函数/静态变量/成员变量(相关示例)
  3. Linux修改文件时候出现崩溃,产生了一个.swap交换文件,如何修复?
  4. WCF 点滴启示录系列(一)
  5. 面向对象下计算器的编码实现
  6. CKEditor和CKFinder配置(asp.net)
  7. yolov3前向传播(一)-- darknet53网络解析与实现
  8. 数据结构笔记(二)--- 顺序实现线性表
  9. OpenCV图像处理(13)——指定区域截取和指定区域复制
  10. 深度学习(01)——安装anaconda