2017-01-23 18 views
0


我有這樣的例子代碼:
與AfterMethod註解Run方法只有在規定的試驗方法TestNG中

public class A { 

@BeforeTest(groups = "group1") 
public void beforeTest() { 
    System.out.println("Before test"); 
} 

@BeforeMethod(groups = "group1") 
public void beforeMethod() { 
    System.out.println("Before method"); 
} 

@Test(groups = { "group1" }) 
public void test1() { 
    System.out.println("Test1"); 
} 

@Test(groups = {"group2"}) 
public void test2() { 
    System.out.println("Test2"); 
} 

@AfterMethod(groups = { "group2" }, alwaysRun = false) 
public void afterMethod() { 
    System.out.println("After method"); 
} 

@AfterTest(groups = "grupa1") 
public void afterTest() { 
    System.out.println("AfterTest"); 
} 
} 

,輸出是:

Before test 
Before method 
Test1 
After method 
Before method 
Test2 
After method 
AfterTest 

但我想收到像這樣的東西:

Before test 
Before method 
Test1 
Before method 
Test2 
After method 
AfterTest 

只有在第二種測試方法之後,有沒有任何選項可以在Method方法後調用?我無法使用afterGroup註釋。

+1

你應該在這裏定製你的解決方案。可能是共享變量/標誌,表示是否運行測試,並將此標誌作爲「After Method」方法中的第一行。 –

回答

0

@AfterMethod替換爲@AfterClass並且您將獲得預期的輸出。

相關問題