Jenkins + qUnit - linux

How to easily integrate Jenkins with qUnit? I gonna use real browser (like firefox and chrome) to run tests. My server runs on RedHat 6.1 Linux. I think I have all needed plugins/libraries but I still don't know how to make it working. I'm working with Jenkins 1st time (on server side).
//Edit:
It would be wonderful if someone can share idea how to build coverage report too.
Thanks in advance :).

Saying Jenkins and QUnit is only part of the puzzle. You still need a web browser and a way to get a JUnit style XML file from the QUnit results on to disk. While there is Selenium and Webdriver for controlling numerous browsers, the easiest way to get started is to use PhantomJS (http://phantomjs.org/). PhantomJS is a headless webkit based browser meant just for tasks like this.
If you browse the "Test Frameworks" sections of this page ( http://code.google.com/p/phantomjs/wiki/WhoUsesPhantomJS ) you will see several scripts for running QUnit (some with JSCoverage support). The phantomjs-jscoverage-qunit script looks like it will hit all the major points you want to hit, as does United. Both look like they will require some fiddling to get them going though.
Alas, I haven't discovered any method for running QUnit tests and getting JUnit output for either Selenium, WebDriver, or PhantomJS that will just work without modification.
EDIT: Now several months later, it have become clear to me that webdriver is the future of Selenium (it probably should have been clear to me back then, but it wasn't). Also, PhantomJS now works with WebDriver via GhostDriver, so supporting only WebDriver and choosing PhantomJS as a target is probably the best advice going forward.

It's been over a year since this question was posted, but there is a Jenkins plugin for TestSwarm. My layman's understanding is that you can use TestSwarm run your QUnit tests continuously across all of the major browsers. It is open sourced on GitHub.

Disclosure: I'm contributor of the Arquillian project.
You can use the Arquillian Qunit Extension open source extension to execute your QUnit tests on Jenkins. In general, Arquillian Qunit Extension can be easily used in continuous integration environments. On this GitHub repo you can find a real example of how Arquillian Qunit Extension can be used to execute QUnit tests on Travis CI headless machines.
Arquillian is a JBoss Community project.
Arquillian Qunit Extension is is an Arquillian extension which automates the QUnit JavaScript testing. Arquillian Qunit Extension integrates transparently with the JUnit testing framework.
You can find more information on this README file. In addition, there is a showcase which can be executed through Maven and shows how to setup your test case.
Using this extension, you have the option to deploy an archive during the QUnit test executions and/or execute one or more QUnit Test Suites in a single execution. Furthermore you can define the QUnit Test Suite execution order using the #InSequence annotation.
For example, assume that you want to execute two QUnit Test Suites (qunit-tests-ajax.html and qunit-tests-dom.html) and that your QUnit tests included in these test suites perform Ajax requests to a Web Service. Apparently, you need this Web Service to be on host while the tests are executed. Arquillian can automatically perform the deployment of the Web Service to a container. In a such case your Arquillian test case will look like:
#RunWith(QUnitRunner.class)
#QUnitResources("src/test/resources/assets")
public class QUnitRunnerTestCase {
private static final String DEPLOYMENT = "src/test/resources/archives/ticket-monster.war";
/**
* Creates the Archive which will be finally deployed on the AS.
*
* #return Archive<?>
*/
#Deployment()
public static Archive<?> createDeployment() {
return ShrinkWrap.createFromZipFile(WebArchive.class, new File(DEPLOYMENT));
}
/**
* Execute the qunit-tests-ajax.html QUnit Test Suite.
*/
#QUnitTest("tests/ticketmonster/qunit-tests-ajax.html")
#InSequence(1)
public void qunitAjaxTests() {
// empty body - only the annotations are used
}
/**
* Execute the qunit-random-tests.html QUnit Test Suite.
*/
#QUnitTest("tests/ticketmonster/qunit-random-tests.html")
#InSequence(2)
public void qunitRandomTests() {
// empty body - only the annotations are used
}
}

If using real browsers:
Run the QUnit tests in multiple browsers simultaneously by using bunyip (https://github.com/ryanseddon/bunyip). It is built on top of Yeti which can provide JUnit XML compatible reports - thus readable by Jenkins
If using PhantomJS (headless browser which acts almost like a real WebKit based one):
Just shared here https://stackoverflow.com/a/17553889/998008 a walk-through on adding QUnit test runner task into Apache Ant build script. Jenkins runs the script while pulling project working copy from a VCS. You need to specify in Jenkins project the location of the output file. Output is JUnit XML compatible.

BlanketJS is a fantastic code coverage tool that works well with QUnit. I've been using it for about a year now.
For Jenkins integration, I use grunt which exits with a 0 if the grunt task fails, and 1 if it passes, so it integrates with Jenkins perfectly.
There was no existing Grunt plugin that handled Blanket and QUnit together, so I wound up writing my own Grunt plugin. The plugin supports "enforcement" of a minimum threshold, or else the Grunt task fails.
I wrote a blog post with all the details here: http://www.geekdave.com/2013/07/20/code-coverage-enforcement-for-qunit-using-grunt-and-blanket/

Related

Custom html page for QUnit test, run with Resharper

Whenever we do kind of integration testing, where our js tests manipulate DOM, we create an html-page with all required DOM-elements, and after that in <script>-tags we define QUnit tests.
Such tests (inside html-files) are not recognized by Resharper runner (it only recognizes QUnit tests inside js-files). We use Chutzpah runner to run QUnit tests which are defined in html-files. However having two runners (Resharper and Chutzpah) does not seem acceptable.
How do you usually handle this (i.e. defining custom pieces of DOM for tests, we don't want to use string constants in JS)? The preference is only having Resharper runner.

Configure project for Jasmine Test Case using Oracle Weblogic

I am having a web based project which I deploy in weblogic server as EAR for execution. I need to implement Jasmine for unit testing.
I came to know that Jasmine can be executed in NodeJS server but my project has some servlets also as a part of it. So, how can I configure Jasmine to run on oracle weblogic server.
Also, if it is possible by any other means like integrating weblogic with NodeJS (I am not sure about this.) , kindly explain me the process to set up.
I wouldn't try to run your Jasmine tests from WebLogic. That is like saying you want to run your JUnit tests on WebLogic.
JUnit tests are run from the command line in your development environment (often wrapped by the IDE) and also on your CI build agent. Jasmine tests should follow the same pattern. You shouldn't have to go through an entire deploy cycle just to run your unit tests.
I suggest looking at using Karma to run your tests, both locally and on CI.

Running Unit Tests on NodeJS with Jenkins

How might I setup Jenkins to start my Node.JS Testing Server, run Unit Test probably JSTestDriver/Jasmine, and then top Node.JS?
I can start Node.JS using Execute Shell, but it "hangs" the build (expected since Node runs as a daemon)
I've written an article that explains how I've managed to run my unit tests with Mocha and ant.
The basic idea is:
Set your environment variables so that jenkins can control them
Use mocha's xunit reporter to generate a result report
Use Jenkins' Publish JUnit test result report option to read the result report.
You can read the full article here.
JSTestDriver outputs it's results in a xUnit compliant xml format. Which the Hudson 'xUnit' plugin can then interpret.
We are planning to integrate jsTestDriver into Jenkins. To test our javaScript code in a selection of supported browsers.
there is a plugin to execute nodejs with possibility to choice the nodejs version
https://wiki.jenkins-ci.org/display/JENKINS/NodeJS+Plugin

Is it possible to integrate Jasmine into cruise control.net

Is it possible to automatically run a jasmine test suite as part of a cruise control.net build?
And If so how?
My server code is C# and I already had my CI server running lots of unit tests. So I added a unit test that uses Watin to launch a browser to run the Jasmine tests and check the results. It took a morning to get all the pieces playing happily together.
An alternative might be to investigate NJasmine -- I saw this was available on NuGet but didn't pursue this myself partly due to lack of documentation.
Also, if you're using ReSharper, you might like to look at their integration with QUnit: http://blogs.jetbrains.com/dotnet/2011/03/resharper-6-introduces-support-for-javascript-unit-testing/ (there's every chance they'll integrate it with Jasmine too). Although this is aimed at running JS UTs within Visual Studio, you might find it offers you a "hook" to run them from your CI server too.

Integrating YUI tests with CruiseControl

I am using YUI to test my JavaScript app, and want to integrate the test results into my CruiseControl build system. How can I use CruiseControl to run the tests? I initially thought about using the JUnit plugin to drive the tests, but that is a no go.
Does anyone else have this working?
(Please note: Changing either YUI or CruiseControl isn't an option for me.)
We have YUI Tests integrated with Hudson for our CI builds. The process should be pretty identical for CC, since we kick off the testing through a Java task in ANT.
We have a selenium driver (a java impl - we're working on making it public) which talks to a SeleniumRC instance, pointing it to the HTML files in build workspace to run tests.
You could take a stab at writing your own selenium driver:
http://seleniumhq.org/docs/05_selenium_rc.html#learning-the-api
The driver code talks to a SeleniumRC instance, and asks it kick off a browser pointing to the YUI Test based HTML test files from the build.
The HTML files run YUI Test Runner on load, and the driver injects code on page load, to pick up test results from YUI Test Runner when it's done running, and store them as files for Hudson to parse.
Regards,
Satyen
YUI Team
My solution, in the end, is a bit of a hack.
I modified our test runner HTML page to post the test results (the entire XML object that it creates) to a PHP page, then to close itself.
I added a PHP page to the build server (with a PHP processor attached to an Apache HTTPD instance) to accept the posted XML document and save it to disk.
The unit tests are now run by a 'test driver', which fires up a browser with the test runner HTML page, and waits for the browser process to end.
This gets the output of the tests onto the local disk of the build server. I then merge the output file into the CC log by adding the following to the project configuration:
<log>
<merge file="path_to_file" />
</log>
There are a few drawbacks, but are (currently) willing to live with them:
Had to introduce a test runner app to the infrastructure
Had to add an Apache server and PHP processor to the build machine
Because only IE will allow a browser page to close itself without a user prompt, the build server must be a Windows machine.

Resources