Sarath
Sarath

Reputation: 1496

Difference between TestNG @BeforeClass and test class constructor

What is the difference between TestNG's @BeforeClass and the test class' constructor? How does it work internally?

Upvotes: 5

Views: 2640

Answers (1)

mies
mies

Reputation: 171

  1. @BeforeClass methods are invoked after test class instantiation.
  2. Exceptions in constructor will just abort TestNG test execution and no report will be created. Whereas exceptions in @BeforeClass will be displayed in resulting report and class test methods will be skipped (This behaviour can be tweaked using -configfailurepolicy TestNG parameter).

Upvotes: 4

Related Questions