Different Types of attributes in TestNG | Use cases | How to use TestNG Attributes

 

TestNGAttributes_SoftwareTesting


What is TestNG Attributes? 

Test Attributes are meta property of Test Classes which are taken into account while running the test cases. This attributes helps us create clean and effective test, set the execution order of test,  run test base on our preference, include or exclude tests and much more.

Some Important Test Attributes 

  • Priority - Priority Attributes in TestNG help us defined which test run at which number. Without setting up the priorities the test will run in the alphabetical order. In the practical applications, running test cases in alphabetical order can terminate all the test cases due to errors.  
TestNGAttributes

TestNGAttributes

  • Description - Using the description attribute, we can easily write the test description for our easy understanding. This help us know the key purposed for that particular test and also it makes reading the test results much easies.

  • Enable - This TestNG attribute is use to skip any particular test case.  (Enable = False >> To skip the test case)

  • Time-Out- This TestNG attribute will time out the test if it takes more than define time

  • Alwaysrun- This TestNG attribute will help us run the test irrespective of other conditions.

  • Depend on Method - This TestNG attribute is help to create test dependencies. For instance, if we are checking an Gmail feature. We  can not check sent email functionality without checking the compose email functionality. This this attributes create dependence as per our test hierarchy. For Example >> Login>dependson>Compose >dependson>Sent

TestNG,Dependencies

Groups - This TestNG attribute helps us run test in Groups. We can create groups of our choice and then can include or exclude those groups to run independent tests. 

To run such specific test by group we need to make changes in the xml file for that suite. 

For Instance>> <groups>

<run>

<include name="Name of group"></include>

</run>

</groups>

Note: This code base need to be run from xml file only.

Comments