views:

40

answers:

3

Maybe you know the simplest way of unit testing javascript functions (not UI like Selenium or WatiN) which can be automated (I prefer using NUnit, eventually NAnt) ? I need to introduce an automated unit test for javascript functions on CruiseControl.NET (so with NUnit and NAnt) - but maybe there is other way ?

Thanks, Dawid

+1  A: 

You can do this with JSUnit. Their JSUnit Server allows you to run scriptable JavaScript unit tests within a Java virtual machine (JVM).

glaxaco
But how to automate it?
+1  A: 

The best way to automate JS tests and include them in continuous integration process is to use JSTestDriver. It is very fast, can test your scripts in all kinds of browsers, can be easily integrated in IDE (How To ntegrate JsTestDriver in Visual Studio), and what is more important - this is simple comsole application, which can be easily be executed from nant script.

The example of solution with JsTestDriver tests is here.

Yauheni Sivukha
It seems promising, but how to capture results later on CC.NET and display them ?
JsTestDriver generates jUnit-compliant XML output. All you need is to register JUnit xsl in CCNET reports. Details: http://code.google.com/p/js-test-driver/wiki/ContinuousBuild
Yauheni Sivukha
OK, I will test it ;) thanks
A: 

You can use Rhino, which is a Javascript runtime written in Java (IIRC, the command-line is something like java -jar Rhino.jar script.js). This is especially useful if your tests don't require a browser.

Don't forget to analyze your JS code with JSLint !

jcmeyrignac