問題描述
這按預期工作,測試失敗(由于 haltTesting())并重復 2 次??p>
This works as supposed, test fails (due to haltTesting()) and is repeated 2x
public class A0001_A0003Test extends TestControl {
private Kunde kunde = Kunde.FR_WEHLITZ;
@Test(retryAnalyzer = TestRepeat.class, groups = {TestGroups.FAILED}, description = "verify adress")
public void testkundenDaten_Angaben() throws Exception {
bifiTestInitial();
testActions.selectKunde(kunde);
haltTesting();
}
}
但是因為我在一個班級中有多個測試,所以我在班級級別定義了 repeatAnalyzer
but because i have multiple tests in one class, i defined the repeatAnalyzer on class level
@Test(retryAnalyzer = TestRepeat.class)
public class A0001_A0003Test extends TestControl {
private Kunde kunde = Kunde.FR_WEHLITZ;
@Test(groups = {TestGroups.FAILED}, description = "verify adress")
public void testkundenDaten_Angaben() throws Exception {
bifiTestInitial();
testActions.selectKunde(kunde);
haltTesting();
}
}
但是沒有重復測試,文檔說:
but then the test is not repeated, the documentation says:
一個類級別的@Test注解的作用是使所有的此類的公共方法成為測試方法,即使它們是沒有注釋.您仍然可以在方法上重復 @Test 注釋如果你想添加某些屬性.
The effect of a class level @Test annotation is to make all the public methods of this class to become test methods even if they are not annotated. You can still repeat the @Test annotation on a method if you want to add certain attributes.
所以這應該是可能的,還是我期待錯誤的結果?
So it should have been possible or am I expecting the wrong outcome?
推薦答案
我的解決方案是為 @BeforeSuite
方法中的所有方法設置一個 retryAnalyzer.但是不要在 beforeMethod 中設置它,因為這樣每次調用都會重新創建一個新的計數器 => 無限循環.
My solution was to set a retryAnalyzer for all methods in the @BeforeSuite
method.
But do not set it in beforeMethod because then it will be re-created each invocation with a new counter => endless loop.
@BeforeSuite(alwaysRun = true)
public void beforeSuite(ITestContext context) {
TestRepeat testRepeat = new TestRepeat();
for (ITestNGMethod method : context.getAllTestMethods()) {
method.setRetryAnalyzer(testRepeat);
}
}
這篇關于TestNG retryAnalyzer 僅在方法@Test 中定義時有效,在類@Test 中無效的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!