RE: Difference between @BeforeMethod , @BeforeClass and @BeforeTest

Answered

What is the diffrance between @BeforeMethod , @BeforeClass and @BeforeTest annotation.

Its bit confusing as all seems same(basically all run before @Test method).

Please elaborate.

rishab Train Asked on August 20, 2014 in Selenium WebDriver.
Add Comment
5 Answers

annotation in testng

if i am using the annotation as beforclass and afterclass
then for all the test  there is only one pre and post condition  within the class

and if i m using the annotation as beforemethod then for all the test with in the class there is one pre and post contiotion

suppose

@beforeclass

public void login()
{

System.out.println(“this is login)
}

@AfterClass

public void logout ()
{

System.out.println(“this is logout)
}

@test(priority=1)
public void Mobilerechrage()
{

System.out.println(my mobile recharge method)

}

@test(priority=2)
public void DISHTVrecharge()
{

System.out.println(“my DISHTVrecharge method”)
}

then the output is for beforeclass and afterclass  annotation is

this is login
my mobile recharge
my DISHTVrecharge method
this is logout

if i am using beformethod  and aftermethod  then output is

this is login
my mobile recharge
this is logout

this is login
my DISHTVrecharge method
this is logout

Default Answered on July 11, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.