[英]How would I produce JUnit test report for groovy tests, suitable for consumption by Jenkins/Hudson?
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 ). 我已经写了几个XMLUnit测试测试(适合在JUnit框架)的常规,可以在命令行上按易执行这些常规DOCO但我不太明白我得为它做还有什么生成Jenkins / Hudson(或其他)所需的xml输出,以显示通过/失败结果( 如此 )和错误的详细报告等( 如此 )。 (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? 我怎样才能创建一个适合Jenkins / Hudson读取的JUnit测试报告xml文件?
Do I need to kick off the tests with a different JUnit runner? 我是否需要使用其他JUnit跑步者开始测试?
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. 经过一段时间的讨论后,我采取了Eric Wendelin的建议,然后选择了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. 为此,我将我的groovy单元测试移动到必需的目录结构src / test / groovy /中,支持资源(输入和预期的输出XML文件)进入/ src / test / resources /目录。
All required libraries have been configured in the build.gradle file, as described (in its entirety) here: 已在build.gradle文件中配置了所有必需的库,如下所述(完整地):
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. 这适用于Groovy插件,设置为使用maven来获取指定的依赖项,然后为内置的“test”任务添加一些额外的值。
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. 还有一件事是最后一行让Gradle每次都运行我的所有测试,而不仅仅是它认为是新的/改变的,这使Jenkins发挥得很好。
I also created a gradle.properties file to get through the corporate proxy/firewall etc: 我还创建了一个gradle.properties文件来通过公司代理/防火墙等:
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. 有了这个,我在Jenkins中创建了一个“自由风格”项目,定期轮询我们的Mercurial仓库,每当有人向仓库提交更新的XSL时,所有测试都将运行。
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 . 我最初的目标之一是能够生成标准的Jenkins / Hudson通过/失败图形和JUnit报告,这是成功的:使用JUnit报告 通过/失败 。
I hope this helps someone else with similar requirements. 我希望这有助于其他有类似要求的人。
I find the fastest way to bootstrap this stuff is with Gradle : 我发现引导这个东西的最快方法是使用Gradle :
# build.gradle
apply plugin: 'groovy'
task initProjectStructure () << {
project.sourceSets.all*.allSource.sourceTrees.srcDirs.flatten().each { dir ->
dir.mkdirs()
}
}
Then run gradle initProjectStructure
and move your source into src/main/groovy
and tests to test/main/groovy
. 然后运行
gradle initProjectStructure
并将源移动到src/main/groovy
并测试test/main/groovy
。
It seems like a lot (really it's <5 minutes of work), but you get lots of stuff for free. 它似乎很多(实际上它是<5分钟的工作),但你可以免费获得很多东西。 Now you can run
gradle test
and it'll run your tests and produce JUnit XML you can use in build/test-reports
in your project directory. 现在您可以运行
gradle test
,它将运行您的测试并生成可在项目目录中的build/test-reports
中使用的JUnit XML。
Since you're asking for the purposes of exposing the report to Jenkins/Hudson, I'm assuming you have a Maven/Ant/etc build that you're able to run. 由于您要求将报告公开给Jenkins / Hudson,我假设您有一个Maven / Ant / etc构建,您可以运行。 If that's true, the solution is simple.
如果这是真的,解决方案很简单。
First of all, there's practically no difference between Groovy and Java JUnit tests. 首先,Groovy和Java JUnit测试之间几乎没有区别。 So, all you need to do is add the Ant/Maven junit task/plugin to your build and have it execute your Groovy junit tests (just as you'd do if they were written in Java).
因此,您需要做的就是将Ant / Maven junit任务/插件添加到您的构建中并让它执行您的Groovy junit测试(就像您用Java编写的那样)。 That execution will create test reports.
该执行将创建测试报告。 From there, you can simply configure your Hudson/Jenkins build to look at the directory where the test reports get created during the build process.
从那里,您可以简单地配置您的Hudson / Jenkins构建,以查看在构建过程中创建测试报告的目录。
You can write your own custom RunListener (or SuiteRunListener ). 您可以编写自己的自定义RunListener (或SuiteRunListener )。 It still requires you to write some code, but it's much cleaner than the script you've provided a link to.
它仍然需要你编写一些代码,但它比你提供链接的脚本要干净得多。 If you'd like, I can send you the code for a JUnit reporter I've written in JavaScript for Jasmine and you can 'translate' it into Groovy.
如果您愿意,我可以向您发送一个JUnit记者的代码,我用JavaScript编写了Jasmine ,您可以将其“翻译”为Groovy。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.