問題描述
這按預(yù)期工作,測(cè)試失敗(由于 haltTesting())并重復(fù) 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();
}
}
但是因?yàn)槲以谝粋€(gè)班級(jí)中有多個(gè)測(cè)試,所以我在班級(jí)級(jí)別定義了 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();
}
}
但是沒有重復(fù)測(cè)試,文檔說:
but then the test is not repeated, the documentation says:
一個(gè)類級(jí)別的@Test注解的作用是使所有的此類的公共方法成為測(cè)試方法,即使它們是沒有注釋.您仍然可以在方法上重復(fù) @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.
所以這應(yīng)該是可能的,還是我期待錯(cuò)誤的結(jié)果?
So it should have been possible or am I expecting the wrong outcome?
推薦答案
我的解決方案是為 @BeforeSuite
方法中的所有方法設(shè)置一個(gè) retryAnalyzer.但是不要在 beforeMethod 中設(shè)置它,因?yàn)檫@樣每次調(diào)用都會(huì)重新創(chuàng)建一個(gè)新的計(jì)數(shù)器 => 無(wú)限循環(huán).
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);
}
}
這篇關(guān)于TestNG retryAnalyzer 僅在方法@Test 中定義時(shí)有效,在類@Test 中無(wú)效的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!