Running QUnit tests with Jenkins and Apache Ant?
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:
<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
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
PS: At the moment, you have to manually delete the JUnit-type XML output file. I will fix this later.
PS: Download the customized qunit.js (https://gist.github.com/2488794)
I've written an Ant task specifically for this