FirstTest.java
Best way to explain TestNG basic is to execute below Script. Please goahead and execute this and let me know if you need any additional clarification.
Sysout has been added to identify sequence of different methods.
testNg.java
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;
public class FirstTest {
@Test(dataProvider = "dp")
public void f(Integer n, String s) {
System.out.println("Inside Data Provider");
}
@BeforeMethod
public void beforeMethod() {
System.out.println("Before Method");
}
@AfterMethod
public void afterMethod() {
System.out.println("After Method");
}
@DataProvider
public Object[][] dp() {
return new Object[][] { new Object[] { 1, "a" },
new Object[] { 2, "b" }, };
}
@BeforeClass
public void beforeClass() {
System.out.println("Before Class");
}
@AfterClass
public void afterClass() {
System.out.println("After Class");
}
@BeforeTest
public void beforeTest() {
System.out.println("Before Test");
}
@AfterTest
public void afterTest() {
System.out.println("After Test");
}
@BeforeSuite
public void beforeSuite() {
System.out.println("Before Suite");
}
@AfterSuite
public void afterSuite() {
System.out.println("After Suite");
}
}
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="Suite" parallel="false">
<test name="Test">
<classes>
<class name="com.jbt.FirstTest"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
output[TestNG] Running: C:\workspace\TestNG\TestNGWebProject\src\TestNG.xml Before Suite Before Test Before Class Before Method Inside Data Provider After Method Before Method Inside Data Provider After Method After Class After Test After Suite =============================================== Suite Total tests run: 2, Failures: 0, Skips: 0 ===============================================
THE CREATING EXPERTS is one of the leading training provider in SELENIUM here is the link
ReplyDeletehttp://thecreatingexperts.com/selenium-training-in-chennai/
contact +91-08122241286
nice blog for selenium Training.,thanks for the info. Share more tutorials and if the readers want to have hands on training with real time scenarios...
ReplyDeleteTHE CREATING EXPERTS
http://thecreatingexperts.com/selenium-training-in-chennai/
contact 8122241286
THE CREATING EXPERTS is one of the leading training provider in SELENIUM they provide hands on training with real time scenario
ReplyDeletehttp://thecreatingexperts.com/selenium-training-in-chennai/
contact +91-08122241286