gpt4 book ai didi

unit-testing - 我将如何生成适合 Jenkins/Hudson 使用的常规测试的 JUnit 测试报告?

转载 作者:行者123 更新时间:2023-12-03 09:24:21 27 4
gpt4 key购买 nike

我已经在 groovy 中编写了几个 XMLUnit 测试(适合 JUnit 框架),并且可以根据 groovy doco 在命令行上轻松执行它们。但我不太明白我还需要做些什么来生成 Jenkins/Hudson(或其他)所需的 xml 输出来显示通过/失败结果(如 this)和详细报告错误等(如 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)

这产生了这样的东西:
Running all XSL Tests...
....
Time: 4.141

OK (4 tests)

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

我是否需要使用不同的 JUnit 运行程序开始测试?

我见过 this回答但想避免必须编写我自己的测试报告输出。

最佳答案

经过一些黑客攻击,我接受了 Eric Wendelin 的建议,并与 Gradle 一起去了。

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

所有必需的库都已在 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"
}

这应用了 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 存储库,每当有人向存储库提交更新的 XSL 时,所有测试都将运行。

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

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

关于unit-testing - 我将如何生成适合 Jenkins/Hudson 使用的常规测试的 JUnit 测试报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9312663/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com