![]() |
VOOZH | about |
@BeforeTest is one of the TestNG Annotations. As the name defines, @BeforeTest is executed before the execution of all the @test annotated methods inside a TestNG Suite. This annotation allows developers to specify various actions to be taken before the execution of all the @test annotated methods inside a TestNG Suite.
Let’s understand the @BeforeTest annotation through an example.
Step 1: In the Maven project, create a TestNG Class that contains @BeforeTest.
Before_Test1.Java
Now, let’s explain what this code does:
beforeTest (@BeforeTest):
Test Methods (@Test):
After performing the operation, the result is printed to the console.
Step 2: Now, we create the AnnotationsTest.xml file to configure the Before_Test1 Class.
Step 3: Run the AnnotationsTest.xml. Right click on the AnnotationsTest.xml file, move the cursor down to Run As and then click on the TestNG Suite.