Friday, January 27, 2012

Introducing QUnitTestDriver

For the past month or so, I've been working on a library to make JavaScript testing integrate better with my company's Java build (junit/maven/jenkins).  All of the options we've tried have been failures because they either don't work well with jQuery or they require an external browser instance which makes them slow and buggy (Selenium, HTMLUnit end-to-end, js-test-driver).

What we really wanted to do was run very fast (sub-100ms) unit tests written in the language of our production code.  This lead us to qUnit.  The problem with qUnit is that there wasn't a convenient way to exercise those tests inside of our normal build easily.  Sure, there is the qunit-test-runner project, but that doesn't come along with any IDE integration.  It requires the tests be run from within an Ant script.

Enter QUnitTestDriver.  It's a simple library allows you to create a plain old jUnit test in any JVM language you choose that points to a plain old qUnit test suite HTML file.  Under the hood, the library lights up a jetty server to avoid "file://" URLs, and uses HTMLUnit to parse the output of the qUnit test results.  Here's an example Java class that would run an entire qUnit test suite that could contain many tests inside of many different files:

public class QUnitTest { @Test public void testPage(){ QUnitTestDriver.run("path/to/qUnitTest.html"); } }
That's it. I hope you find this useful!

You can find out more about the project on it's new Google Code Site Here.

No comments:

Post a Comment

AddThis

Bookmark and Share