我想下面的代碼:dependsOnMethods爲@AfterTest沒有找到測試方法
public class ShashiTest {
@Test
public void test1(){
System.out.println("1===========");
}
@Test(dependsOnMethods="test1")
public void test2(){
System.out.println("2===========");
}
@Test(dependsOnMethods="test2")
public void test3(){
System.out.println("3===========");
}
@AfterMethod(dependsOnMethods={"test2","test3"})
public void test4(){
System.out.println("4===========");
}
}
我期待輸出:
1===========
2===========
4===========
3===========
4===========
但我得到異常的測試方法未找到:
com.ShashiTest.test4() is depending on method public void com.ShashiTest.test2(), which is not annotated with @Test or not included.
at org.testng.internal.MethodHelper.findDependedUponMethods(MethodHelper.java:111)
我在哪裏犯錯誤?我如何實現我的目標?
請參閱下面的Julien Herr的回答。一個快速的觀察:一旦你開始取決於多種方法,我建議依賴於組,而這更容易維護。但你絕對看起來在這裏找到了一個bug。 –