当单元测试失败时从 Hudson 发送电子邮件

发布于 2024-12-08 19:16:43 字数 256 浏览 5 评论 0原文

我在 hudson 构建后运行 Selenium 单元测试。并想用它来监控我的网站功能。

当构建成功时(应该总是成功,因为它只包含单元测试),即使某些测试失败,hudson 也不会发送电子邮件。

使用 email-ext,我可以在它变得不稳定时发送电子邮件,但由于浏览器单元测试有些不稳定,我不希望在第一次失败时发送电子邮件,更像是连续 3 次或最后 x 分钟/运行的 80%

最好的配置是基于基于测试名称的规则集或测试中定义的将其标记为相关的内容。

I am running Selenium unittests after my hudson build. And want to use it for monitoring my websites functionality.

When the build succeeds (which should be always, since it only contains the unittests), hudson will not send emails, even when some tests fail.

With email-ext, I could send emails when it becomes unstable, but since browser unittests are somewhat flaky, I do not want them at the first failure, more something like 3 in a row or 80% of the last x-Minutes/runs

Best would be a configuration based on a ruleset based on the testname or something defined in the test which marks it as relevant..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冰雪梦之恋 2024-12-15 19:16:43

如果单独构建不稳定/仍然不稳定,那么使用脚本来设置邮件内容怎么样?

在这里,您可以添加一些if条件来单独测试所需测试用例的年龄。

<%  if(build.testResultAction) {
    def rootUrl = hudson.model.Hudson.instance.rootUrl
    def jobName = build.parent.name

    def previousFailedTestCases = new HashSet()
    def currentFailedTestCase = new HashSet()

    if(build.previousBuild?.testResultAction){
        build.previousBuild.testResultAction.failedTests.each {
            previousFailedTestCases << it.simpleName +"." + it.safeName
        }
    }

    testResult.failedTests.each{tr ->
          def packageName = tr.packageName
          def className = tr.simpleName
          def testName = tr.safeName
          def displayName = className+"."+testName

          currentFailedTestCase << displayName
          def url = "$HUDSON_URL/job/$PROJECT_NAME/$BUILD_NUMBER/testReport/$packageName/$className/$testName"
          if(tr.age == 1){
            startedFailing << [displayName:displayName,url:url,age:1]
          } else{
            failing << [displayName:displayName,url:url,age:tr.age]
          }
    }

    startedPassing = previousFailedTestCases - currentFailedTestCase

    startedFailing = startedFailing.sort {it.displayName}
    failing = failing.sort {it.displayName}
    startedPassing = startedPassing.sort()
    } %>

源链接: http ://techkriti.wordpress.com/2008/08/30/using-groovy-with-hudson-to-send-rich-text-email/

What about using a script for setting the mail content in case of unstable/still-unstable builds alone?

Here, you can add some if conditions for testing the age for the required test cases alone.

<%  if(build.testResultAction) {
    def rootUrl = hudson.model.Hudson.instance.rootUrl
    def jobName = build.parent.name

    def previousFailedTestCases = new HashSet()
    def currentFailedTestCase = new HashSet()

    if(build.previousBuild?.testResultAction){
        build.previousBuild.testResultAction.failedTests.each {
            previousFailedTestCases << it.simpleName +"." + it.safeName
        }
    }

    testResult.failedTests.each{tr ->
          def packageName = tr.packageName
          def className = tr.simpleName
          def testName = tr.safeName
          def displayName = className+"."+testName

          currentFailedTestCase << displayName
          def url = "$HUDSON_URL/job/$PROJECT_NAME/$BUILD_NUMBER/testReport/$packageName/$className/$testName"
          if(tr.age == 1){
            startedFailing << [displayName:displayName,url:url,age:1]
          } else{
            failing << [displayName:displayName,url:url,age:tr.age]
          }
    }

    startedPassing = previousFailedTestCases - currentFailedTestCase

    startedFailing = startedFailing.sort {it.displayName}
    failing = failing.sort {it.displayName}
    startedPassing = startedPassing.sort()
    } %>

Source link : http://techkriti.wordpress.com/2008/08/30/using-groovy-with-hudson-to-send-rich-text-email/

梦亿 2024-12-15 19:16:43

当构建成功时(应该总是成功,因为它只包含单元测试),hudson 不会发送电子邮件,即使某些测试失败。

我不知道这是否是您想要修复的问题,但如果您使用参数,

-Dmaven.test.failure.ignore=false

那么如果测试失败,Hudson 将使您的构建失败。

使用 email-ext,当它变得不稳定时,我可以发送电子邮件,但由于浏览器单元测试有点不稳定,我不希望它们在第一次失败时出现,更像是连续 3 个或最后一个 x- 的 80%分钟/运行

您的单元测试是分钟/运行?这更像是性能测试而不是单元测试吗?如果它不是单元测试,而是性能/负载测试,我们使用 JMeter(Hudson 有一个插件,Maven 也有)效果很好,它允许我们设置 % 何时将构建设置为不稳定或失败。

When the build succeeds (which should be always, since it only contains the unittests), hudson will not send emails, even when some tests fail.

I don't know if this is something you want to fix, but if you use the argument

-Dmaven.test.failure.ignore=false

Then Hudson will fail your build if a test fails.

With email-ext, I could send emails when it becomes unstable, but since browser unittests are somewhat flaky, I do not want them at the first failure, more something like 3 in a row or 80% of the last x-Minutes/runs

Your unit tests are minutes/runs? Is this more a performance test than a Unit Test? If it's less a Unit Test and more a Performance / Load Test, we've used JMeter (Hudson has a plugin, as does Maven) with great effect, which allows us to set % when to set the build as unstable or failed.

涫野音 2024-12-15 19:16:43

听起来你在哈德逊需要两份工作。一种用于单元测试,一种用于硒。

您希望第一份工作构建并运行单元测试,并让 hudson 报告单元测试。

在“构建后操作”下的配置中,您可以添加“要构建的项目”并指定构建和运行 selenium 并报告这些结果的作业。

通过这种方式,您可以调整单元测试的电子邮件阈值,使其比您的硒结果严格得多。

It sounds like you need two jobs in hudson. One for unittests and one for selenium.

You want the first job to build and run the unittests and have hudson report on the unittests.

In the configuration under "post build actions" you can add a "project to build" and specify your job that builds and runs selenium and reports on those results.

This way you can tweak the thresholds for emails for unit tests to be far more strict than your selenium results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文