Reading:  

Working with TestNG - Starters Guide


Annotations

Annotations are keywords which are used in TestNG code which gives information about test methods  which methods are going to run before & after test methods or test will be ignore during execution.

Here is a quick overview of some of the annotations available in TestNG along with their attributes.

Data source: TestNG Docs 

 @Test

 This annotation identifies the following method as test method.

 @BeforeTest

Method which is annotated as “@BeforeTest” sothis method is executed before each test annotation method is executing. It is basically used to prepare test environment, initializing, resources etc.

 @AfterTest

Method which is annotated as “@AfterTest” so this method is executed after each test annotation method is executed. It is basically used for clean-up/un initializing the resources/releasing.

 @BeforeMethod

Method which is annotated as “@BeforeMethod” will be run before each and every test method.

 @AfterMethod

Method which is annotated as “@AfterMethod” will be run after each and every test method.

 @BeforeClass

Method which is annotated as “@BeforeClass” so this method is executed only once before executing all the test annotation methods executed. This method needs to be defined as “static”

 @AfterClass

Method which is annotated as “@AfterClass” so this method is executed only once after executing all the test annotation methods executed. This method needs to be defined as “static”

 @BeforeSuite

Method which is annotated as “@BeforeSuite” so this method will be run only once before all tests in this suiterun

 @AfterSuite

Method which is annotated as “@AfterSuite” so this method will be run only once after all tests in this suite have run completely.

 @BeforeGroups

This method is run before the first test method that belongs to any groups is invoked.

 @AfterGroups

This method is run after the all test methods that belongs to groups is executed completely.

 @Factory

If a method is annotated as a factory, returns objects that will be used by TestNG as Test classes.

 @DataProvider

If a method is annotated as DataProvider, It Marks it as supplying data for a test method.

 @Parameters

This annotated method used to pass parameters to a @Test method.           

 @Listeners

This annotated method used to define the listeners on a test class. 

Annotations - What are they good for:

  • It allows user to pass additional parameters to annotations.
  • Annotations are in-built keywords if any mistake in keywords, the compiler will give errorright away.
  • There is no restriction on TestNGmethod names format.

Description

This tutorial is focused on getting you started on TestNG, the testing framework inspired from JUnit and NUnit. Here is a quick table of contents

  1. What is TestNG?
  2. Environment Set-up
  3. Writing Tests
  4. Basic Annotations
  5. Execution Procedure
  6. Executing Tests
  7. Suite Test
  8. Ignore Test
  9. Group Test
  10. Exception Test
  11. Dependency Test
  12. Parametrized Test
  13. JUnit Tests
  14. Test Reports
  15. Running tests without Eclipse
  16. Plugin with ANT

 

 



Environment

A computer capable of running Java. IntelliJ Community IDE is also required for this course.

Prerequisites

Good knowledge of Java programming language and eclipse is essential.

Audience

Students looking to get started with TestNG

Learning Objectives

This tutorial will get you started with TestNG.

Author: Subject Coach
Added on: 12th Mar 2015

You must be logged in as Student to ask a Question.

None just yet!