如何在Junit 5上重试参数化测试?
我有一个片状的参数化测试,如果在测试运行时实际上说失败之前,我想重试几次。片状有充分的理由(这与并发状况和少量竞赛条件有关,这不会总体上影响该系统),因此我不需要消除片状。
在Junit 4中,我们可以设置规则,在该规则中,我设置了一种“重试规则”,该规则会在失败之前重试测试X次数。但是,在Junit 5中已经消失了,到目前为止,我所看到的唯一解决方案涉及正常的Junit 5测试,而不是参数化测试。在Junit 5中重试参数化测试的最佳方法是什么?
I have a flaky parameterized test that I want to retry a couple of times if it fails before actually saying fail when the test runs. There is good reason for the flakiness (it has to do with concurrency and small chance race conditions which does not overall affect the system) so no I don't need to remove the flakiness.
In JUnit 4 we could set up rules in which I set up a sort of "Retry rule" that retries the test x number of times before failing. However, in JUnit 5 that's gone and the only solutions I've seen so far involve normal JUnit 5 tests and not parameterized tests. What's the best way to retry a parameterized test in JUnit 5?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
则可以使用Junit-Pioneer库重试的
如果您使用的是Maven, :
您可以在pom.xml中指定此内容
,对于参数tatest,您可以在现有的@parameterized -Test注释之上添加额外的@retryingTest(3)注释:
对于正常测试,您可以用@retryingtest替换@test(3) )
虽然3是您希望在失败尝试时重试的尝试数量,并且您可以将其更改为指定的其他数字
https://junit-pioneer.org/docs/retrying-test/
you can use junit-pioneer library for retrying
if you are using maven:
you can specify this in your pom.xml
and for your ParameterizedTest, you can add the extra @RetryingTest(3) annotation on top of your existing @ParameterizedTest annotation like this:
and for normal test you can replace @Test with @RetryingTest(3)
while 3 is the number of attempts you wish to retry upon failure attempts, and you can change it to different number that you specified
https://junit-pioneer.org/docs/retrying-test/
看起来您期望使用
@parameterizedRepeatEdifeXeftionStestest
来自 rerunner-jupiter”> rerunner-jupiter 一个>扩展。尽管扩展名的读数说Java 8是必需的,但是当我在Java 17中进行测试时,核心功能(参数和重复)确实可以正常工作。依赖性:(gradle)
样本测试:
该测试的写入是接受4个输入,并且第一个和最后一个输入两次失败。总共将执行测试8次 - 第一个和最后一个输入每次三次,第二个输入和第三个输入。从下面的Gradle进行测试日志:
Looks like what you expect can be achieved using
@ParameterizedRepeatedIfExceptionsTest
from rerunner-jupiter extension. Though the extension's readme says Java 8 is required, the core functionality(parameters and repeat) did work fine when I tested in Java 17.Dependency: (gradle)
Sample test:
The test is written to accept 4 inputs and fail twice for the first and last inputs. In total, the test will be executed 8 times - thrice each for the first and last inputs, once each for the second and third inputs. Test logs from gradle below: