Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
281 views
in Interview Questions by The go-to Tester (181 points)

Can you explain about TestNG's beforeClass, beforeMethod, afterClass, beforeSuite and afterSuite?

1 Answer

0 like 0 dislike
by The go-to Tester (181 points)
As the name says,

beforeClass - This is used to invoke before class activities, in case you are using one test per class, or yo - Thu want to execute all tests in class in one browser you can initiate browser instence at class level.

afterClalss- If you are using before class, we use afterClass to complte activity we started.

beforeMethod - In case of you need to start certain activity before method, such as initiating browser, logging in, initiating reporting instence, before each test, we use beforeMethod.

afterMethod- This is used in case to complete certain actions to be completed after @Test method is over

beforeSute - This is utilized to initiate stuff before Suite, such as reading TestNG.xml file and getting list of parameters, initiating report directory, purging cache, etc.

afterSuite This is utilized to initiate after execution activity such as writing report files, zipping and emailing the same.


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...