In previous post we have seen how to do setup and run through simple testng file, in this post we will try to understand different annotations in TestNG
Ex. in TestNG xml file below would be hierarchy or Annotations levels in TestNG.
<Suite>
<test>
<Classes>
<Method>
<test>
</method>
</Classes>
</test>
</Suite>
Above hierarchy talks about @Test is the smallest annotation here. @Method will be executed first, before and after the execution of @Test. The same way @Class will be executed first, before and after the execution of @Method and so on.
Let's create a simple example and run the same
Output :
I will execute before the Test Suite
I will execute Before any Test method/case executes
I will execute after test and test suite -
I will be executed before Each Test Method
This is the Test Case 1
I will be executed before Each Test Method
I will be executed before Each Test Method
This is the Test Case 2
I will be executed before Each Test Method
This will execute after the Class
I will execute After all Test method/case executes
PASSED: testCase1
PASSED: testCase2
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
This will execute after the Test Suite
Ex. in TestNG xml file below would be hierarchy or Annotations levels in TestNG.
<Suite>
<test>
<Classes>
<Method>
<test>
</method>
</Classes>
</test>
</Suite>
Above hierarchy talks about @Test is the smallest annotation here. @Method will be executed first, before and after the execution of @Test. The same way @Class will be executed first, before and after the execution of @Method and so on.
Let's create a simple example and run the same
Output :
I will execute before the Test Suite
I will execute Before any Test method/case executes
I will execute after test and test suite -
I will be executed before Each Test Method
This is the Test Case 1
I will be executed before Each Test Method
I will be executed before Each Test Method
This is the Test Case 2
I will be executed before Each Test Method
This will execute after the Class
I will execute After all Test method/case executes
PASSED: testCase1
PASSED: testCase2
===============================================
Default test
Tests run: 2, Failures: 0, Skips: 0
===============================================
This will execute after the Test Suite
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.