如果它们失败,请重新运行不稳定的JUnit测试 [英] Rerun flaky JUnit test in case they failed

查看:72
本文介绍了如果它们失败,请重新运行不稳定的JUnit测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在詹金斯(Jenkins)有一个作业A,用于自动化测试,如果另一个作业B构建成功,则会触发该作业.作业A运行了几个测试.有些测试很不稳定,所以我想再次运行几次,让它们有通过的机会,这样我的构建就不会不稳定/失败.

I have a job A in Jenkins for my automated testing that is triggered if another job B build is successful. The job A run several tests. Some of the test are flaky so I would like to run them again few times and let them the chance to pass so my build won't be unstable/failed.

我可以使用任何插件吗?

Is there any plugin I can use?

推荐答案

我建议修复或重写测试,以使它们仅在发生故障时才会失败.也许您可以嘲笑那些可能会失败的事情.如果您要终止数据库连接,则可以使用本地的sqlite或smething.

I would suggest to fix your tests or rewrite them so they will only fail if something is broken. Maybe you can mock away the things that tend to fail. If you are depnending on a database connection, maybe you could use a sqlite or smething which is local.

但是还有一个可以重试构建的插件: https://wiki.jenkins-ci.org/display/JENKINS/Naginator+插件

But there is also a plugin which can retry a build: https://wiki.jenkins-ci.org/display/JENKINS/Naginator+Plugin

只需安装插件,然后在项目的配置页面上检查生成后尝试重试构建"操作.

Simply install the plugin, and then check the Post-Build action "Retry build after failure" on your project's configuration page.

如果要在JUnit上下文中重新运行测试,请在此处查看:

If you want to rerun tests in JUnit-context, take a look here: SO: How to Re-run failed JUnit tests immediately?

这篇关于如果它们失败,请重新运行不稳定的JUnit测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆