- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How will you run a prerequisite method and post condition method for
every test in TestNG?
We can run a prerequisite method and post condition method for every test in TestNG with the help of @BeforeMethod and @AfterMethod annotations.
Example
@BeforeMethod public void prerequisite(){ System.out.println("Run before every tests"); } @AfterMethod public void postcondition(){ System.out.println("Run after every tests "); } @Test public void loanPay(){ System.out.println("Loan pay is successful"); }
In the Java class file, the prerequisite() method with @BeforeMethod will be executed which is known as the precondition for every test method. Then loanPay() will be executed and finally the postcondition() method with @AfterMethod will run.
- Related Articles
- How to get the name of a test method that was run in a TestNG teardown method?
- How does running a specific test method depend on another test method in TestNG?
- How to skip a particular test method in TestNG?
- How to run test groups in TestNG?
- How to run multiple test classes in TestNG?
- How to overlook a particular test method from execution in TestNG?
- How does TestNG invoke a test method using multiple threads?
- How to retrieve test method description in TestNG before and after execution?
- How to retrieve test method name in TestNG before and after execution?
- How to disable a TestNG test based on a condition?
- How to run multiple test cases using TestNG Test Suite in Selenium?
- How does the execution of a particular test method depend on other test\nmethods in TestNG?
- How to run a test method without reporting as passed or failed in pytest?
- How will you test for sugar and protein in a food item?
- How to specify method name sequence in TestNG?

Advertisements