
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 Questions & Answers
- How to get the name of a test method that was run in a TestNG teardown method?
- How to run test groups in TestNG?
- 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 multiple test classes in TestNG?
- How to disable a TestNG test based on a condition?
- How does TestNG invoke a test method using multiple threads?
- How to run a method every 10 seconds in Android?
- How to overlook a particular test method from execution in TestNG?
- How to run multiple test cases using TestNG Test Suite in Selenium?
- 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 run a method every 10 seconds in Android using Kotlin?
- How does the execution of a particular test method depend on other test methods in TestNG?
- How to execute a particular test method multiple times (say 5 times) in TestNG?
Advertisements