第二章 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 tag is run.
@AfterTest: The annotated method will be run after all the test methods belonging to the classes inside the 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.
Behaviour of annotations in superclass of a TestNG class
The annotations above will also be honored (inherited) when placed on a superclass of a TestNG class. This is useful for example to centralize test setup for multiple test classes in a common superclass.
In that case, TestNG guarantees that the "@Before" methods are executed in inheritance order (highest superclass first, then going down the inheritance chain), and the "@After" methods in reverse order (going up the inheritance chain).
  alwaysRun

For before methods (beforeSuite, beforeTest, beforeTestClass and beforeTestMethod, but not beforeGroups): If set to true, this configuration method will be run regardless of what groups it belongs to.

对于before方法(beforeSuite, beforeTest, beforeTestClass和beforeTestMethod,但不包括beforeGroups):如果设置为true,无论该配置方法属于哪个组,它都将运行。

For after methods (afterSuite, afterClass, ...): If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped.

对于after方法(afterSuite, afterClass,…):如果设置为true,则即使先前调用的一个或多个方法失败或被跳过,也会运行此配置方法。

dependsOnGroups

The list of groups this method depends on.

此方法所依赖的组列表。

dependsOnMethods

The list of methods this method depends on.

此方法所依赖的方法列表。

enabled

Whether methods on this class/method are enabled.

是否启用这个类/方法上的方法。

groups

The list of groups this class/method belongs to.

该类/方法所属的组列表。

inheritGroups

If true, this method will belong to groups specified in the @Test annotation at the class level.

如果为true,该方法将属于在类级别的@Test注释中指定的组。

onlyForGroups

Only for @BeforeMethod and @AfterMethod. If specified, then this setup/teardown method will only be invoked if the corresponding test method belongs to one of the listed groups.

只适用于@BeforeMethod和@AfterMethod。如果指定了,那么只有当相应的测试方法属于列出的组之一时,才会调用这个setup/teardown方法。

 
@DataProvider

Marks a method as supplying data for a test method. The annotated method must return an Object[][] where each Object[] can be assigned the parameter list of the test method. The @Test method that wants to receive data from this DataProvider needs to use a dataProvider name equals to the name of this annotation.

将一个方法标记为测试数据的提供方法。用该注解标记的方法必须返回一个Object[][],其中每个Object[]可以被分配测试方法的参数列表。测试方法要从指定的数据驱动方法接收数据需要使用@Test(dataProvider = "dataProviderMethodName")来指定。

  name

The name of this data provider. If it's not supplied, the name of this data provider will automatically be set to the name of the method.

为数据提供方法指定一个名称。如果没有指定,则以此方法名作为数据提供方法的名称。

parallel

If set to true, tests generated using this data provider are run in parallel. Default value is false.

如果设置为true,则使用此数据提供方法的测试将并行执行。该属性默认值为false。

 
@Factory

Marks a method as a factory that returns objects that will be used by TestNG as Test classes. The method must return Object[].

将一个方法标记为一个工厂,该工厂返回将被TestNG用作测试类的对象。该方法必须返回Object[]。

 
@Listeners

Defines listeners on a test class.

在测试类上定义侦听器。

  value

An array of classes that extend org.testng.ITestNGListener.

一个继承org.testing.itestnglistener的类数组。

 
@Parameters

Describes how to pass parameters to a @Test method.

描述如何将参数传递给@Test方法。

  value

The list of variables used to fill the parameters of this method.

用于填充此方法的参数的变量列表。

 
@Test Marks a class or a method as part of the test.
  alwaysRun

If set to true, this test method will always be run even if it depends on a method that failed.

如果取值为true,那么不论这个测试方法依赖的前置测试是否成功都会执行当前的方法。

dataProvider

The name of the data provider for this test method.

取值为测试方法的数据驱动方法的名称(@DataProvider中name参数的值,没有使用name属性时则为@DataProvider注解的方法名)。

dataProviderClass

The class where to look for the data provider. If not specified, the data provider will be looked on the class of the current test method or one of its base classes. If this attribute is specified, the data provider method needs to be static on the specified class.

取值为数据驱动方法所在的类名。如果未指定,将在当前测试方法的类或其基类之一上查找数据驱动方法。 需要配合dataProvider属性一起使用。

dependsOnGroups

The list of groups this method depends on.

指定当前测试方法所依赖的组。

dependsOnMethods

The list of methods this method depends on.

指定当前测试方法所依赖的方法。

description

The description for this method.

测试方法的说明,会在报告中显示。

enabled

Whether methods on this class/method are enabled.

是否执行该类/方法上的测试。

expectedExceptions

The list of exceptions that a test method is expected to throw. If no exception or a different than one on this list is thrown, this test will be marked a failure.

期望测试方法将引发的异常列表。如果未抛出异常或此列表中的异常,则该测试将标记为失败。

groups

The list of groups this class/method belongs to.

该类/方法所属的组。

invocationCount

The number of times this method should be invoked.

应该调用此方法的次数。

invocationTimeOut

The maximum number of milliseconds this test should take for the cumulated time of all the invocationcounts. This attribute will be ignored if invocationCount is not specified.

对于所有调用计数的累积时间,该测试应花费的最大毫秒数。如果未指定invocationCount,则将忽略此属性。

priority

The priority for this test method. Lower priorities will be scheduled first.

指定测试方法的优先级。值小的先执行。

successPercentage

The percentage of success expected from this method

该方法预期成功的百分比。

singleThreaded

If set to true, all the methods on this test class are guaranteed to run in the same thread, even if the tests are currently being run with parallel="methods". This attribute can only be used at the class level and it will be ignored if used at the method level. Note: this attribute used to be called sequential (now deprecated).

如果设置为true,则此测试类上的所有方法都保证在同一线程中运行,即使测试当前正在使用parallel="methods"运行。这个属性只能在类级别上使用,如果在方法级别上使用,它将被忽略。注意:这个属性过去被称为sequential(现在已弃用)。

timeOut

The maximum number of milliseconds this test should take.

当前测试方法的超时时间。

threadPoolSize

The size of the thread pool for this method. The method will be invoked from multiple threads as specified by invocationCount.

指定方法的线程池的大小。该方法将从invocationCount指定的多个线程中调用。注意:如果未指定invocationCount,则忽略此属性。

Note: this attribute is ignored if invocationCount is not specified

注意:如果未指定invocationCount,则忽略此属性

你可能感兴趣的:(testng,java,测试工具,testng)