我将如何为常规测试生成JUnit测试报告,适合Jenkins / Hudson使用? [英] How would I produce JUnit test report for groovy tests, suitable for consumption by Jenkins/Hudson?

查看:144
本文介绍了我将如何为常规测试生成JUnit测试报告,适合Jenkins / Hudson使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Groovy中编写了几个XMLUnit测试(适合于JUnit框架),并且可以根据 groovy doco 但我不太明白我还需要做些什么才能生成Jenkins / Hudson需要的xml输出(或其他)显示合格/不合格结果(如)和详细的错误报告等(如这个)。 (对图片所有者表示歉意)



目前,我的kickoff脚本是这样的:

  def allSuite = new TestSuite('The XSL Tests')

//查看包xsltests.rail。*
allSuite.addTest(xsltests / rail ,* Tests.groovy))

junit.textui.TestRunner.run(allSuite)

,并产生如下所示:

 运行所有XSL测试... 
.. ..
时间:4.141

确定(4次测试)

我怎样才能创建一个适合Jenkins / Hudson读取的JUnit测试报告xml文件?



我是否需要用不同的JUnit运行器启动测试?



我已经看过这个回答,但想避免不得不写我自己的测试报告输出。

解决方案

经过一些小事后,我采取了Eric Wendelin的suggestio为了做到这一点,我把我的groovy单元测试移到了必需的目录结构src / test / groovy /中,其中包含了支持资源(输入和输出预期的输出XML文件)进入/ src / test / resources /目录。

所有必需的库已经在build.gradle文件中配置,全部):

  apply plugin:'groovy'

repositories {
mavenCentral )
}

依赖项{
testCompile组:'junit',name:'junit',版本:'4. +'

groovy模块('org.codehaus.groovy:groovy:1.8.2'){
dependency('asm:asm:3.3.1')
dependency('antlr:antlr:2.7.7')
依赖('xmlunit:xmlunit:1.3')
依赖('xalan:serializer:2.7.1')
依赖('xalan:xalan:2.7.1')
依赖org.bluestemsoftware.open.maven.tparty:Xerces的-IMPL:2.9 .0')
依赖('xml-apis:xml-apis:2.0.2')
}
}

测试{
jvmArgs' -Xms64m','-Xmx512m','-XX:MaxPermSize = 128m'

testLogging.showStandardStreams = true //不知道这个,是在官方用户指南

outputs.upToDateWhen {false} //使它每次运行即使Gradle认为它是最新的
}

这适用Groovy插件,设置为使用maven抓取指定的依赖关系,然后向内置的测试任务添加一些额外的值。

这里有一件额外的事情是让Gradle每次运行我所有的测试,而不仅仅是它认为是新的/改变的测试,这让Jenkins可以玩很好。



我还创建了一个gradle.properties文件来通过企业代理/防火墙等:

  systemProp.http.proxyHost = 10.xxx.xxx.xxx 
systemProp.http.proxyPort = 8080
systemProp.http.proxyUser = username
systemProp。 http.proxyPassword = passwd

有了这个,我在Jenkins中创建了一个'free-style'项目我们定期轮询我们的Mercurial回购协议,并且每当有人提交更新的XSL到回购时,所有的测试都将运行。



我最初的目标之一是能够生成标准Jenkins / Hudson通过/未通过图形和JUnit报告,这是成功的:通过/失败 JUnit Reports



我希望这可以帮助其他有类似要求的人。 / p>

I've written several XMLUnit tests (that fit in to the JUnit framework) in groovy and can execute them easily on the command line as per the groovy doco but I don't quite understand what else I've got to do for it to produce the xml output that is needed by Jenkins/Hudson (or other) to display the pass/fail results (like this) and detailed report of the errors etc (like this). (apologies to image owners)

Currently, my kickoff script is this:

def allSuite = new TestSuite('The XSL Tests')

//looking in package xsltests.rail.*
allSuite.addTest(AllTestSuite.suite("xsltests/rail", "*Tests.groovy")) 

junit.textui.TestRunner.run(allSuite)

and this produces something like this:

Running all XSL Tests...
....
Time: 4.141

OK (4 tests)

How can I make this create a JUnit test report xml file suitable to be read by Jenkins/Hudson?

Do I need to kick off the tests with a different JUnit runner?

I have seen this answer but would like to avoid having to write my own test report output.

解决方案

After a little hackage I have taken Eric Wendelin's suggestion and gone with Gradle.

To do this I have moved my groovy unit tests into the requisite directory structure src/test/groovy/, with the supporting resources (input and expected output XML files) going into the /src/test/resources/ directory.

All required libraries have been configured in the build.gradle file, as described (in its entirety) here:

apply plugin: 'groovy'

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.+'

    groovy module('org.codehaus.groovy:groovy:1.8.2') {
        dependency('asm:asm:3.3.1')
        dependency('antlr:antlr:2.7.7')
        dependency('xmlunit:xmlunit:1.3')
        dependency('xalan:serializer:2.7.1')
        dependency('xalan:xalan:2.7.1')
        dependency('org.bluestemsoftware.open.maven.tparty:xerces-impl:2.9.0')
        dependency('xml-apis:xml-apis:2.0.2')
    }
}

test {
    jvmArgs '-Xms64m', '-Xmx512m', '-XX:MaxPermSize=128m'

    testLogging.showStandardStreams = true //not sure about this one, was in official user guide

    outputs.upToDateWhen { false } //makes it run every time even when Gradle thinks it is "Up-To-Date"
}

This applies the Groovy plugin, sets up to use maven to grab the specified dependencies and then adds some extra values to the built-in "test" task.

One extra thing in there is the last line which makes Gradle run all of my tests every time and not just the ones it thinks are new/changed, this makes Jenkins play nicely.

I also created a gradle.properties file to get through the corporate proxy/firewall etc:

systemProp.http.proxyHost=10.xxx.xxx.xxx
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=passwd

With this, I've created a 'free-style' project in Jenkins that polls our Mercurial repo periodically and whenever anyone commits an updated XSL to the repo all the tests will be run.

One of my original goals was being able to produce the standard Jenkins/Hudson pass/fail graphics and the JUnit reports, which is a success: Pass/Fail with JUnit Reports.

I hope this helps someone else with similar requirements.

这篇关于我将如何为常规测试生成JUnit测试报告,适合Jenkins / Hudson使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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