Pre conditions and PostConditions in Test Ng.
Vision of Preconditions and Postconditions:
👉 Ensuring Test Isolation:
By using preconditions and postconditions, you ensure that each test method is executed in isolation, with a clean and consistent state.
👉Promoting Reusability:
Setup and teardown tasks defined in preconditions and postconditions can be reused across multiple test methods, promoting code reuse and reducing redundancy.
👉Maintainability:
Clearly defined preconditions and postconditions enhance the maintainability of test code. Changes or additions to the setup and cleanup logic can be made centrally in these annotated methods.
TestNG PreConditions and PostConditions flow.
- Before Suite (once)
- Before Test (once for each
<test>in the suite)- Before Class (once for each class with test methods in the
<test>)- Before Method (before each test method)
- Test method execution
- After Method (after each test method)
- Before Method (before each test method)
- After Class (after all test methods in the class within the
<test>)
- Before Class (once for each class with test methods in the
- After Test (after all tests in the suite)
- Before Test (once for each
- After Suite (once)
Comments
Post a Comment