testng_TestNG注释

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值