Home page

Thursday, July 6, 2023

TestNG Annotations

Regular annotations are used in TestNG to specify how test methods should behave and progress. They let you customize a number of test execution settings and give the testing framework more data. Here are several normal annotations in TestNG that are frequently used and what they are used for:

@Test:

Purpose: Marks a method as a test method.

Usage: This annotation is used to indicate that a specific method should be considered a test method by the TestNG framework.

@BeforeSuite:

Purpose: Defines a method to run before the execution of all test suites.

Usage: This annotation is used when you need to set up any global configuration or resources that are required before running any tests.

@AfterSuite:

Purpose: Defines a method to run after the execution of all test suites.

Usage: This annotation is used when you need to perform cleanup or teardown activities after executing all tests, such as releasing resources or generating reports.

@BeforeTest:

Purpose: Specifies a method to run before the execution of each test tag or test XML file.

Usage: This annotation is useful when you need to perform setup activities specific to a particular test or group of tests.

@AfterTest:

Purpose: Specifies a method to run after the execution of each test tag or test XML file.

Usage: This annotation allows you to perform cleanup or teardown activities specific to a particular test or group of tests.

@BeforeClass:

Purpose: Defines a method to run before the first test method in a test class.

Usage: This annotation is used when you need to set up any preconditions or initialize resources that are required for all test methods in a class.

@AfterClass:

Purpose: Defines a method to run after the execution of all test methods in a test class.

Usage: This annotation is used when you need to perform cleanup or teardown activities that are common to all test methods in a class.

@BeforeMethod:

Purpose: Specifies a method to run before each test method execution.

Usage: This annotation is used when you need to set up any preconditions or initialize resources specific to each test method.

@AfterMethod:

Purpose: Specifies a method to run after each test method execution.

Usage: This annotation is used when you need to perform cleanup or teardown activities specific to each test method.

No comments:

Post a Comment