TestNG retryAnalyzer only works when defined in methods @Test, does not work in class#39; @Test(TestNG retryAnalyzer 仅在方法@Test 中定义时有效,在类@Test 中无效)
问题描述
这按预期工作,测试失败(由于 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 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:TestNG retryAnalyzer 仅在方法@Test 中定义时有效,在类@Test 中无效


- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01