javascript 使用 Jenkins 和 Apache Ant 运行 QUnit 测试?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10275476/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running QUnit tests with Jenkins and Apache Ant?
提问by Agile Ace
Is it possible to execute my QUnit (javascript) unit tests from Jenkins? My build script is Apache Ant. Would Jenkins execute this as a separate Build Step, or would I need to add something in the config of my Ant build script?
是否可以从 Jenkins 执行我的 QUnit (javascript) 单元测试?我的构建脚本是 Apache Ant。Jenkins 会将此作为单独的构建步骤执行,还是我需要在 Ant 构建脚本的配置中添加一些内容?
回答by Agile Ace
So, I have finally managed to figure this out.
所以,我终于设法弄清楚了这一点。
Here's my end-to-end implementation:
这是我的端到端实现:
Install PhantomJS (http://phantomjs.org/) - I installed this in my build/tools folder
Install the PhantomJS QUnit Runner script (https://gist.github.com/1588423) - also installed this in my build/tools folder
Added the following target to my build.xml file:
安装 PhantomJS ( http://phantomjs.org/) - 我将它安装在我的 build/tools 文件夹中
安装 PhantomJS QUnit Runner 脚本 ( https://gist.github.com/1588423) - 也安装在我的 build/tools 文件夹中
将以下目标添加到我的 build.xml 文件中:
<target name="qunit" description="runs QUnit tests using PhantomJS">
<!-- QUnit Javascript Unit Tests -->
<echo message="Executing QUnit Javascript Unit Tests..."/>
<apply executable="path-to-your-phantomjs-bin-folder/phantomjs" >
<arg value="-path-to-your-build-tools/qunit-runner.js" />
<arg line="--qunit path-to-your-qunit-folder/qunit.js --tests path-to-your-test-folder --juni path-where-you-want-to-write-the-JUnit-style-output/qunit-results.xml" />
<fileset dir="${basedir}/${dir.test}" includes="tests.js" />
<srcfile/>
</apply>
</target>
Under my Jenkins project config, I now invoke Ant with "minify qunit"
I point Jenkins to the JUnit-style output XML file
在我的 Jenkins 项目配置下,我现在使用“minify qunit”调用 Ant
我将 Jenkins 指向 JUnit 样式的输出 XML 文件
And, here is the workflow:
而且,这是工作流程:
- Check changes into my repo
- Jenkins will poll GitHub for changes
- If there are any changes, Jenkins will pull down
- Ant will be invoked, doing the build, then running my unit tests
- The test results will be published in a JUnit-like XML format
- Jenkins will analyse this output file. If no tests failed, the build will be marked as "Success". If any tests failed, the build will be marked as "Unstable"
- Jenkins will deploy the web changes
- Jenkins will cleanup the work-area
- 检查更改到我的回购
- Jenkins 将轮询 GitHub 以了解更改
- 如有变动,Jenkins会拉下来
- Ant 将被调用,进行构建,然后运行我的单元测试
- 测试结果将以类似 JUnit 的 XML 格式发布
- Jenkins 将分析这个输出文件。如果没有测试失败,构建将被标记为“成功”。如果任何测试失败,构建将被标记为“不稳定”
- Jenkins 将部署 Web 更改
- Jenkins 将清理工作区
PS: At the moment, you have to manually delete the JUnit-type XML output file. I will fix this later.
PS:目前,您必须手动删除 JUnit 类型的 XML 输出文件。我稍后会解决这个问题。
PS: Download the customized qunit.js (https://gist.github.com/2488794)
PS:下载定制的 qunit.js ( https://gist.github.com/2488794)
回答by Phil Mander
I've written an Ant task specifically for this
我专门为此编写了一个 Ant 任务
回答by malenkiy_scot
回答by hwjp
Qunit itself now maintains a phantomjs runner:
Qunit 本身现在维护着一个 phantomjs runner:
https://github.com/jquery/qunit/tree/master/addons/phantomjs
https://github.com/jquery/qunit/tree/master/addons/phantomjs
So assuming you've already installed phantomjs, grab runner.jsfrom the link above (or get it using bower/whatever js package manager), put it somewhere jenkins can find it, and then use:
所以假设你已经安装了 phantomjs,从上面的链接中获取runner.js(或者使用 bower/任何 js 包管理器获取它),把它放在 jenkins 可以找到的地方,然后使用:
phantomjs path/to/runner.js path/to/your/qunit_tests.html
It gives minimal output like this:
它提供了这样的最小输出:
$ phantomjs superlists/static/tests/runner.js accounts/static/tests/tests.html
Took 29ms to run 11 tests. 11 passed, 0 failed.
Or like this if it fails:
或者像这样如果失败:
$ phantomjs superlists/static/tests/runner.js accounts/static/tests/tests.html
Test failed: sinon tests of navigator.id.watch: watch sees current user
Failed assertion: check user, expected: current user, but was: baz
at file:///home/harry/superlists/superlists/static/tests/qunit.js:556
at file:///home/harry/superlists/accounts/static/tests/tests.html:69
at file:///home/harry/superlists/superlists/static/tests/qunit.js:203
at file:///home/harry/superlists/superlists/static/tests/qunit.js:361
at process (file:///home/superlists/superlists/static/tests/qunit.js:1453)
at file:///home/harry/superlists/superlists/static/tests/qunit.js:479
Took 29ms to run 11 tests. 10 passed, 1 failed.
No junit-xml integration, but at least it returns an error code if it fails, so it'll fail the build in jenkins...
没有 junit-xml 集成,但至少它会在失败时返回一个错误代码,所以它会在 jenkins 中构建失败......
$ echo $?
1