@BeforeTest
|
@BeforeMethod
|
To execute a set-up method before any of the test methods
included in the
< test > tag in the testng.xml file. |
To execute a set-up method before any of the test methods
annotated as
@Test . |
Example Testng.xml :
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE suite
SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite"
parallel="none">
<test name="test">
<classes>
<class name=".BeforetestandBeforemethod">
<methods>
<include name="toBeforeTest"></include>
<include name="toBeforeMethod"></include>
</methods>
</class>
</classes>
</test>
<methods>
</suite> <!-- Suite
-->
|
Example Java code such as:
import
org.testng.annotations.BeforeMethod;
import
org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class
BeforetestandBeforemethod {
@BeforeTest
public void beforeTest() {
System.out.println("@BeforeTest");
}
@BeforeMethod
public void beforemethod(){
System.out.print("@BeforeMethod");
}
public void helper() {
System.out.println("Flow");
}
@Test
public void toBeforeMethod() {
helper();
System.out.println("BeforeMethod");
}
@Test
public void toBeforeTest() {
helper();
System.out.println("BeforeTest");
}
}
|
Execute code by TestNG, then the Output would be:
When run <include name="toBeforeTest"></include>
Run <include name="toBeforeMethod"></include>