QUnit, Selenium and Continuous Integration
Most of the organizations these days understand the importance of unit testing and use it heavily in their project. Unit testing frameworks are available for most of the high-level languages like JUnit for Java, NUnit for .NET, pyunit for Python and so on. These unit testing tools have now reached a level of maturity and most of us have probably used them in some capacity. Unit testing Java Script is unfortunately, still a bit tricky and its integration with other tools is also not well known. In this article, I will try to explore how QUnit framework for testing Java Script can be integrated with Selenium and continuous Integration.
QUnit is a unit testing framework for JavaScript. It is capable of testing the JQuery code and server side code as well. QUnit tests require loading of the javascripts in the browser so even though they are unit tests their integration with CI (Continuous Integration) is a bit tricky. Since their integration with CI is tricky, most of the time these Qunit tests end up in some shared drives. They could be extremely useful and well written tests, but in the absence of their integration with the build process, their full potential is often not be realized.
Fortunately, there are more than one ways of calling these Qunit tests. Most of them follow the same concept of wrapping Qunit tests in some unit testing framework which could be integrated with CI. In this post I will explain integration of QUnit tests with Hudson build server using Selenium. I have followed the post of integrating the Qunit tests with CI from here.
Qunit tests are .html files containing method calls to some javascript files. Selenium would open these .html pages in the browser and look for the id ‘testresults’. This is the unique Id of the test results in the Qunit tests html file. Selnium can check if there are any failures in the end results. If there are any failure Selenium will report this as failure. I have wrapped these selenium tests in the TestNG unit testing framework.
The next thing is to write a bit of Maven Pom file for executing these selenium tests. Once you write a pom file to run the selenium tests you have integrated Qunit tests with CI using selenium. This will allow you to see the QUnit failures in Hudson just like any other JUnit / Test NG or Selenium Tests.
Gotchas
When I tried to open the Qunit .html file from C:drive or my local drive I was always prompted for the ActiveX control by Internet explorer. So I put the tests in the shred folder and used a UNC path to access the tests and I was able to get rid of the prompt.
BTW, if you need information on how to use hudson slaves to execute your selenium tests, its covered here and if you want to understand QUnit in detail, you can read it at evil tester's site.
Do you like this post?
Subscribe to receive new posts via RSS or email. Join!

