以下は私のXMLファイルとDemoクラスです。 Demo1()メソッドの前にPrecondition()メソッドが実行され、demo1()メソッドの後にpostCondition()メソッドが実行されます。同じプロセスがdemo2()です。しかし、コードを実行すると、BeforeSuiteメソッドとBeforeTestメソッドは呼び出されません。なぜ。?それらを呼び出す方法?TestNGでグループを実行すると@Before Suiteと@BeforeTestメソッドは呼び出されません
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
あなたの質問に答えてくれたら、私の答えを受け入れてください。 –
ありがとう、これを探している –