TestNG Annotations

 

@BeforeSuite
@AfterSuite
@BeforeTest
@AfterTest
@BeforeGroups
@AfterGroups
@BeforeClass
@AfterClass
@BeforeMethod
@AfterMethod
Configuration information for a TestNG class: 

@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.

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).

 alwaysRunFor 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. 
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.
 dependsOnGroupsThe list of groups this method depends on.
 dependsOnMethodsThe list of methods this method depends on.
 enabledWhether methods on this class/method are enabled.
 groupsThe list of groups this class/method belongs to.
 inheritGroupsIf true, this method will belong to groups specified in the @Test annotation at the class level.
 onlyForGroupsOnly 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.
 
@DataProviderMarks 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.
 nameThe 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.
 parallelIf set to true, tests generated using this data provider are run in parallel. Default value is false.
 
@FactoryMarks a method as a factory that returns objects that will be used by TestNG as Test classes. The method must return Object[].
 
@ListenersDefines listeners on a test class.
 valueAn array of classes that extend org.testng.ITestNGListener.
 
@ParametersDescribes how to pass parameters to a @Test method.
 valueThe list of variables used to fill the parameters of this method.
 
@TestMarks a class or a method as part of the test.
 alwaysRunIf set to true, this test method will always be run even if it depends on a method that failed.
 dataProviderThe name of the data provider for this test method.
 dataProviderClassThe 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.
 dependsOnGroupsThe list of groups this method depends on.
 dependsOnMethodsThe list of methods this method depends on.
 descriptionThe description for this method.
 enabledWhether methods on this class/method are enabled.
 expectedExceptionsThe 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.
 groupsThe list of groups this class/method belongs to.
 invocationCountThe number of times this method should be invoked.
 invocationTimeOutThe 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.
 priorityThe priority for this test method. Lower priorities will be scheduled first.
 successPercentageThe percentage of success expected from this method
 singleThreadedIf 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).
 timeOutThe maximum number of milliseconds this test should take.
 threadPoolSizeThe size of the thread pool for this method. The method will be invoked from multiple threads as specified by invocationCount. 
Note: this attribute is ignored if invocationCount is not specified
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值