Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Continuous integration / Testing of Javascript code against different browsers

I am writing a set of functions in Javascript meant to be executed inside a browser (no server-side Javascript).

How to run unit and perfomance tests agains them in different browsers, and keep track of the results for every build?

  • Tests should be executed within a browser
  • Test results should be produced as a stand alone text or html file
  • Target browsers are Internet Explorer 7 and 8, latest Firefox, latest Chrome, latest Safari
  • I am free to setup a dedicated CI server and virtual machines if needed
like image 767
lbz Avatar asked Dec 05 '10 14:12

lbz


4 Answers

I have been using Jasmine framework for the testing and JSTestDriver. I had also set up both Hudson and TeamCity for CI as part of evaluation, though eventually settled on TeamCity.

Jasmine is a very nice BDD framework, which also provides mocking and stubbing functionality.

JSTestDriver server allows any browser to attach to it, whether local, or remote, as Vojta has already pointed out. I have been able to connect browsers from Windows and MAC machines for example, and also iPhone ... it is quite possible to connect other mobile browsers, if mobile development tickles your fancy. JSTestDriver will produce JUnit XML results files that either Hudson or TeamCity will be able to parse and report upon.

As Vojta also pointed out, an Eclipse plugin is available for JSTestDriver. I have recently moved over to WebStorm 1.0 and now 2.0 (IDE from JetBrains), and a plugin exists for this IDE as well, albeit somewhat buggy. WebStorm is excellent, btw, as far as JavaScript development is concerned.

We are also writing server-side JS code, and Jasmine has worked fine here as well.

I have installed and configured JsTestDriver/TeamCity on the Amazon cloud and I am able to run Jasmine tests headlessly, for example.

In short, between the 3 solutions (Jasmine, JSTestDriver, and TeamCity), tons of plugins/adapters/recipes exist that allow any number of setups or configurations. That is not to say other combinations will not work ... simply, for me, this combinations has proven itself thus far.

like image 130
Ireney Berezniak Avatar answered Nov 04 '22 18:11

Ireney Berezniak


Hi you may take a look a JQunit, a javascript unit testing framework based on JQuery. Available here http://code.google.com/p/jqunit/

like image 26
Alexandre GUIDET Avatar answered Nov 04 '22 19:11

Alexandre GUIDET


Jasmine (http://pivotal.github.com/jasmine) is a dependency-free BDD framework for testing JavaScript.

It would be pretty easy to use Jasmine & the Jasmine Ruby gem to setup a matrix of runs against the different browsers (Selenium drives the browser in the gem) and reporting them via your CI as you suggest. Should be straightforward.

like image 31
user533109 Avatar answered Nov 04 '22 20:11

user533109


I'm using JsTestDriver for JS developing. It's a test runner (not unit test framework), so you can use it together with Jasmine, or QUnit.

You simply start a server and capture browsers (could be remote browser as well !) and then run tests on all these browsers through command line.

There is a nice plugin for eclipse as well.

For more information, how to set up continuous build environment, see http://code.google.com/p/js-test-driver/wiki/ContinuousBuild

like image 1
Vojta Avatar answered Nov 04 '22 18:11

Vojta