2017-09-25 14 views
2

以下は私の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 --> 

答えて

2

@BeforeSuite@BeforeTestはすべての時間を実行していることを確実にするために、これらのアノテーションの属性alwaysRun=trueを有効にしてください。

スルーグループを実行する場合、これらの設定方法は、選択したグループの一部でない限り、TestNGによって選択されない可能性があるためです。

TestNGのグループ選択は、実行するテストを決定する際に、TestNGにフィルタリングの基準を伝えることを可能にする、TestNGのフィルタリングメカニズムの一種として視覚化することができます。

+0

ありがとうございました。 @Krishnan。これは助けてくれました – naqash

+0

あなたの質問に答えてくれたら、私の答えを受け入れてください。 –

+0

ありがとう、これを探している –

関連する問題