JsTestDriver First Impressions

I’m currently trying to get some unit tests written around a bunch of JavaScript code and I’m using JsTestDriver to do it. So far, I’m pretty impressed though there are some little gotchas here and there. It’s been a really good framework for basic testing assuming you aren’t doing a ton of work with other libraries like Prototype.js and script.aculo.us which of course I am. I’m sure there are ways around it but it’s going to take some digging to figure out what they are.

One minor thing that has been different for me from the documentation is that when I try to run tests, I need to specify the server explicitly on the command line even though I have a server running and a browser captured. The documentation says you can do this:

java -jar JsTestDriver.jar --tests all


However, I’ve found that I need to do:

java -jar JsTestDriver.jar --tests all --server http://localhost:9876

Where the server value may be different according to what server you started up.

Now I’m off to figure out how I can mock some of the Prototype.js dependencies.

5 comments on “JsTestDriver First Impressions

  1. Hi,

    Have you managed to mock up some Prototype.js dependencies or jQuery?

    I see JsTestDriver-1.2.1-src.jar came out Feb 27th, has that sorted out a few gotchas you encountered?

  2. Darren :

    Have you managed to mock up some Prototype.js or jQuery dependencies y?
    I see JsTestDriver-1.2.1-src.jar came out Feb 27th, has that sorted out a few gotchas you encountered?

  3. Niklaus Wirth's Ghost

    March 31, 2010 at 9:33 am Reply

    Hi Darren,

    I ended up not mocking anything out and instead just including dependencies in the script file containing my tests. So for example, in tests where Prototype.js is required, I just add the following line to the top of my test script file:


    That seems to work currently though I haven’t been spending too much time with JsTestDriver lately and am just now getting back into it.

  4. Hi all,
    I found this site after searching for a solution how to use JsTestDriver with prototype.js. I tested the approach to inject the prototype file at each test file but without success in my case. Don’t ask why but it looks like the injection was performed to late to init the tests proper.

    Later I found this way to hack prototype and enable it for JsTestDriver: http://code.google.com/p/js-test-driver/issues/detail?id=32#c12
    Looks like the JSON part is a problem right now. I’m not using the fix which is also mentioned in this thread. I just add a fix.js file in the conf file and that’s it.

    Maybe this will help someone later facing the same problem I did.
    By the way: I’m using the eclipse plugin of JsTestDriver.

    Cheers, Joerg

  5. I was having a similar issue with needing to set the server explicitly. What I found was that there was a non-printable character at the begining of the config file as a result from copying from web references. Creating a clean file and typing up the config cleared up the issue.

    I’m having trouble with using the –browser flag to auto capture different browsers. Have you gotten that to work for you?

Leave a Reply

Your email address will not be published. Required fields are marked *