Annotations in testng (Annotations)

Source: Internet
Author: User

The annotations in testng greatly facilitate the organization of test cases and test methods. Taking into account the special use of the usual, so from the official documents reproduced, and take into account the gradual translation, in case of a rainy future.

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

@BeforeSuite:The annotated method would be a run before all tests in this suite has run.
@AfterSuite:The annotated method would be a run after any tests in this suite has run.
@BeforeTest: The annotated method would be a run before any test method belonging to the classes inside the <test> tag is run.
@AfterTest: The annotated method would be run after all the test methods belonging to the classes inside the <test> tag has RU N.
@BeforeGroups: The list of groups that this configuration method would run before. This method was guaranteed to run shortly before the first test method, belongs to any of these groups are invoked.
@AfterGroups: The list of groups that this configuration method would run after. This method was guaranteed to run shortly after the last test method, the belongs to any of the these groups are invoked.
@BeforeClass: The annotated method would be a run before the first test method in the current class is invoked.
@AfterClass: The annotated method would be a run after all the ' test methods in the ' current class has been run.
@BeforeMethod: The annotated method would be is run before each test method.
@AfterMethod: The annotated method would be is run after each test method.
Alwaysrun For before methods (Beforesuite, Beforetest, Beforetestclass and Beforetestmethod, but not beforegroups): If set to True, This configuration method would be is run regardless of what groups it belongs to.
For after methods (Aftersuite, Afterclass, ...): If set to True, the This configuration method would be run even If one or more Methods invoked previously failed or was skipped.
Dependsongroups The list of groups this method is depends on.
Dependsonmethods The list of methods this method is depends on.
Enabled Whether methods on this class/method is enabled.
Groups The list of groups this Class/method belongs to.
Inheritgroups If true, this method would belong to groups specified in the @Test annotation at the class level.
@DataProvider Marks a method as supplying data for a test method. The annotated method must return a object[][] where each object[] can is assigned the parameter list of the test method. The @Test method, wants to receive data from this dataprovider needs to use a dataprovider name equals to the name of this annotation.
Name The name of this data provider. If It's not a supplied, the name of this data provider would automatically be set to the name of the method.
Parallel If set to True, the tests generated using this data provider is run in parallel. Default value is false.
@Factory Marks a method as a factory that returns objects that would be used by TestNG as Test classes. The method must return object[].
@Listeners Defines listeners on a test class.
Value An array of classes that extend org.testng.ITestNGListener.
@Parameters Describes how to pass parameters to a @Test method.
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, the this test method would always be the run even if it depends on a method that failed.
Dataprovider The name of the data provider for this test method.
Dataproviderclass The class where to look for the data provider. If not specified, the data provider would be looked on the class of the current test method or one of its base classes. If This attribute was specified, the data provider method needs to was static on the specified class.
Dependsongroups The list of groups this method is depends on.
Dependsonmethods The list of methods this method is depends on.
Description The description for this method.
Enabled Whether methods on this class/method is enabled.
Expectedexceptions The list of exceptions. A test method is expected to throw. If no exception or a different than one on the this list was thrown, this test would be marked a failure.
Groups The list of groups this Class/method belongs to.
Invocationcount The number of times this method should is invoked.
Invocationtimeout The maximum number of milliseconds this test should take for the cumulated time of the invocationcounts. This attribute would be ignored if invocationcount are not specified.
Priority The priority for this test method. Lower priorities would be scheduled first.
Successpercentage The percentage of success expected from this method
singlethreaded If set to true, all the methods on this test class is guaranteed to run in the same thread, even if the tests is current Ly being run with parallel= "methods". This attribute can is used at the class level and it is ignored if used at the method level. Note:this attribute used to is called sequential (now deprecated).
TimeOut The maximum number of milliseconds this test should take.
ThreadPoolSize The size of the thread pool for this method. The method is invoked from multiple threads as specified by Invocationcount.

Annotations in testng (Annotations)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.