Let's consider the state of JavaScript unit tests and testing tools.
JsUnit
We already use it for some of our js code.
Pros
- can be invoked from an ant build file
- launches browser to run the tests
Eclipse plug-in
Cons
launches browser to run the tests
- Does not support js file to write the unit test code: it has to be embedded inside an html file
- it has not be updated for a few years
Note: There is a JsUnit (2).
RhinoUnit
Pros
- ant driven
- supports js file
very simple to use
Cons
Simulation of JavaScript engine: not advanced enough to support our code: I tried to run test code working with JsUnit: I encountered issue when loading our common JavaScript files
crosscheck
Pros
- Can invoked from ant build file
Simulates real browser behaviour
Cons
Simulation of JavaScript engine from a limited number of browser versions
- No activity for 2 years: it does not support Firefox versions 2.x nor 3.x
jsspec
Pros
Runs on actual browser
Cons
JavaScript only framework: cannot be called from ant build file
jspec
Pros
Runs on actual browser
Cons
Does not seem to support our code: I tried to run test code running with js unit: I encountered issue when loading our common JavaScript files
- JavaScript only framework: cannot be called from ant build file,
Screw.unit
Pros
Runs on actual browser
Cons
JavaScript only framework: cannot be called from ant build file
Note: I did not try it but it is very similar to jsspec and jspec.
It looks like JsUnit is the only choice we have. Please note it is already used in other components. It is not perfect though because it does not provide an easy way to apply the TDD process for the following reasons: - It does not provide a simple and integrated way to run JavaScript unit test - It forces you to write the unit tests in a html file instead of a .js file, - It forces you to have a local installation of the JsUnit framework in order to avoid absolute hard coded path to reference js unit files.
As a consequence, you have to switch back and forth from you IDE and all the browsers we want to support while "TDDing" in JavaScript. It is feasible but I do not think it is very effective (I may be wrong here).
Also I still need to look at a proper JavaScript editor or Eclipse plug-in allowing easy referencing and refactoring. There is the JSTD one which is part of WTP, however I have not played with it enough in order to have a good idea of it.
As a conclusion, I do not think we have the tools to be fully "TDD" compliant. We can be TOD (Test Oriented Development), but I have not found any tool that allows us to work with JavaScript as efficiently as with Java. Once again, the ideal solution would be to have something identical to JUnit.
What JavaScript unit testing tools do you use?
Recent Entries: