2
下面是我的XML文件和Demo類。在demo1()方法和postCondition()方法將在demo1()方法之後運行之前,Precondition()方法將運行。 demo2()的過程相同。但是當我運行代碼時,BeforeSuite和BeforeTest方法不會被調用。爲什麼。?如何給他們打電話?@Before Suite和@BeforeTest方法在TestNG中執行時不會被調用
Output :
Before Method is executing
DEMO -1
After Method is executing
Before Method is executing
DEMO 2
After Method is executing
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name = "Hey"></include>
</run>
</groups>
<classes>
<class name="practicepackage.Demo"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
package practicepackage;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class Demo {
@BeforeSuite
public void beforeSuite(){
System.out.println("Before Suite method is being launched");
}
@BeforeTest
public void beforeTest(){
System.out.println("Before Test Method is being luanched");
}
@BeforeMethod(groups = {"Hey"})
public void PreCondition(){
System.out.println("Before Method is executing");
}
@Test (groups = {"Hey"})
public void demo1(){
System.out.println("DEMO -1 ");
}
@Test(groups = {"Hey"})
public void demo2(){
System.out.println("DEMO 2");
}
@AfterMethod(groups = {"Hey"})
public void postCondition(){
System.out.println("After Method is executing");
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite">
<test name="Test">
<groups>
<run>
<include name = "Hey"></include>
</run>
</groups>
<classes>
<class name="practicepackage.Demo"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
謝謝你的幫助。 @Krishnan。這幫了我很多 – naqash
如果能幫助回答你的問題,請接受我的回答。 –
謝謝,找這個 –