What is the difference between BeforeClass and BeforeTest in TestNG - Selenium WebDriver, please suggest me best link or site for this.
This is a duplicate question of below :
since you asked site to refer please consider below websites:
You can refer below link:
@BeforeTest method runs before the test method, belonging to the classes inside the tag. It is called once for each test tag. It is used to initialize common objects between different test classes inside one test tag.
@BeforeClass method runs before the class is invoked. It is called once for each test class inside the test tag. It is used to initialize common objects between different test methods inside one test class.
<suite name="suit1"> <test name="TestTag1"> <classes> <class name="TestClass1"/> </classes> </test> <test name="TestTag2"> <classes> <class name="TestClass2"/> <class name="TestClass3"/> </classes> </test> </suite>
@BeforeTest will be called twice, one time before
TestTag1 the second time before
@BeforeClass will be called three times, one time before
TestClass1 the second time before
TestClass2 and the third time before