我一直试图让Jenkins显示一个示例js项目的JUnit报告,我正在用QUnit进行测试。我确实在互联网上搜索过零碎的东西,到目前为止,Running QUnit tests with Jenkins and Apache Ant?是我发现的最有帮助的帖子。
我可以证实:
不过,我仍然不能让report.xml生成,以便将其输入Jenkins。下面是我添加到我的build.xml文件中的目标:
<target name="qunit" description="runs QUnit tests using PhantomJS">
<!-- QUnit Javascript Unit Tests -->
<echo message="Executing QUnit Javascript Unit Tests..."/>
<apply executable="/usr/local/CI/phantomjs/bin/phantomjs" >
<arg value="/usr/local/CI/phantomjs-runner/runner.js" />
<arg line="--qunit /usr/local/CI/jenkins/workspace/PhantomJS/web/js/qunit-1.17.1.js --tests /usr/local/CI/jenkins/workspace/PhantomJS/web/index.html --junit /usr/local/CI/jenkins/workspace/PhantomJS/test-results/report.xml" />
<fileset dir="${basedir}/web/" includes="/js/prettydate.js" />
<srcfile/>
</apply>
<echo message="Tests complete..."/>
</target>在Jenkins中编译这个项目给了我以下输出:
?PhantomJS/result.xml?PhantomJS /test-使用本地配置的密码连接到:pserver:user@server:/cvsroot cvs rlog -S -S -d18 2015年2月15:49:54 +0000<18 2015年2月15:51:40 +0000 QUnit_Jenkins PhantomJS$ /usr/local/CI/ant/bin/ant:+0000<18 回音执行QUnit Javascript单元测试。回声测试完成..。 生成成功的总时间:0秒记录测试结果测试报告,但没有一个是新的。测试运行了吗?例如,/usr/local/CI/jenkins/workspace/PhantomJS/test-results/report.xml是4小时18分钟的时间。 生成步骤“发布JUnit测试结果报告”将生成结果更改为失败完成:失败
正如您可能注意到的,jenkins找不到更新的report.xml文件,因为根本没有生成一个文件。
你能观察到我的build.xml中有什么错误吗?如果没有,有什么想法和提示可以帮助我生成result.xml文件?
发布于 2015-02-27 12:02:53
我通过采取以下步骤,找到了解决我的答案的办法:
1)添加了生成报表所需的<script src="js/qunit-reporter-junit.js"></script>。确保您也包含了qunit.js库。我用了qunit-1.17.1.js
2)我在测试js代码的html文件中放置了以下代码:
<script>
QUnit.jUnitReport = function(report) {
console.log(report.xml)
};
</script>3)我在build.xml文件中添加了Ant代码:
<target name="build" description="runs QUnit tests using PhantomJS">
<!-- Clean up output directory -->
<delete dir="./build/qunit"/>
<mkdir dir="./build/qunit"/>
<!-- QUnit Javascript Unit Tests -->
<echo message="Executing QUnit Javascript Unit Tests..."/>
<exec executable="/usr/local/CI/phantomjs/bin/phantomjs" output="./build/qunit/qunit-results.xml">
<arg value="/usr/local/CI/phantomjs-runner/runner-muted.js"/>
<arg value="./web/index.html"/>
</exec>
</target>您将注意到,我将runner.js的名称更改为Run-muted.js--这是这样的,因为我已经对runner.js进行了更改,使其不包括输出到xml文件,因为这使得jenkins无法读取它。为此:
我希望这能帮助你们中的任何一个人让它发挥作用。
https://stackoverflow.com/questions/28588380
复制相似问题