Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/unit-testing/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing 如何为groovy测试生成适合Jenkins/Hudson使用的JUnit测试报告?_Unit Testing_Groovy_Junit_Hudson_Jenkins - Fatal编程技术网

Unit testing 如何为groovy测试生成适合Jenkins/Hudson使用的JUnit测试报告?

Unit testing 如何为groovy测试生成适合Jenkins/Hudson使用的JUnit测试报告?,unit-testing,groovy,junit,hudson,jenkins,Unit Testing,Groovy,Junit,Hudson,Jenkins,我已经在groovy中编写了几个XMLUnit测试(适合JUnit框架),并且可以根据在命令行上轻松地执行它们,但是我不太明白为了生成Jenkins/Hudson(或其他人)显示通过/失败结果(如)所需的xml输出,我还需要做些什么以及错误的详细报告等(如)。(向图像所有者道歉) 目前,我的开场白是: def allSuite = new TestSuite('The XSL Tests') //looking in package xsltests.rail.* allSuite.addTe

我已经在groovy中编写了几个XMLUnit测试(适合JUnit框架),并且可以根据在命令行上轻松地执行它们,但是我不太明白为了生成Jenkins/Hudson(或其他人)显示通过/失败结果(如)所需的xml输出,我还需要做些什么以及错误的详细报告等(如)。(向图像所有者道歉)

目前,我的开场白是:

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)
这就产生了这样的结果:

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

OK (4 tests)
如何创建适合Jenkins/Hudson读取的JUnit测试报告xml文件

我需要用不同的JUnit跑步者开始测试吗


我已经看到了答案,但希望避免编写自己的测试报告输出。

既然您要求将报告公开给Jenkins/Hudson,我假设您有一个可以运行的Maven/Ant/etc构建。如果这是真的,那么解决方案很简单


首先,Groovy和JavaJUnit测试之间几乎没有区别。因此,您只需将Ant/Maven junit任务/插件添加到构建中,并让它执行Groovy junit测试(就像用Java编写测试一样)。该执行将创建测试报告。从那里,您可以简单地配置Hudson/Jenkins构建,以查看在构建过程中创建测试报告的目录。

您可以编写自己的自定义(或)。它仍然需要您编写一些代码,但它比您提供链接的脚本要干净得多。如果您愿意,我可以向您发送我用JavaScript编写的JUnit reporter的代码,您可以将其“翻译”为Groovy

我发现引导这些东西的最快方法是:

#build.gradle
应用插件:“groovy”
任务initProjectStructure()
目录mkdirs()
}
}
然后运行
gradleinitprojectstructure
,将源代码移动到
src/main/groovy
,并将测试移动到
test/main/groovy


看起来很多(真的是经过一点修改后,我接受了埃里克·温德林的建议,和格雷德尔一起走了

为此,我将groovy单元测试移动到必需的目录结构src/test/groovy/,支持资源(输入和预期的输出XML文件)进入/src/test/resources/目录

所有必需的库都已在build.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创建了一个“自由风格”项目,定期轮询Mercurial repo,每当有人向repo提交更新的XSL时,所有测试都将运行

我最初的目标之一是能够生成标准的Jenkins/Hudson及格/不及格图形和JUnit报告,这是一个成功:with


我希望这能帮助其他有类似需求的人。

您是否使用了一些测试框架?您使用什么来构建项目?是否对使用Gradle/Maven/Ant这样的构建工具有任何反感?@Eric这是一个附带项目,希望能够快速启动和运行。不过,我可能会继续学习和使用Gradle,因为它在我的“学习内容”领域。不,我没有像Maven或Ant那样使用构建框架,它只是一个单元测试的集合。没有构建,只有一系列测试,希望每次启动时都有一个通过/失败的记录。感谢使用Gradle的小小推动。而我的答案(很明显)解决了我的问题,50磅的赏金是你的。谢谢:)-我想你会喜欢格拉德尔的。
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"
}
systemProp.http.proxyHost=10.xxx.xxx.xxx
systemProp.http.proxyPort=8080
systemProp.http.proxyUser=username
systemProp.http.proxyPassword=passwd