Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Test automation for Javascript

 
Rupa Lahiri
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can testing of Javascript be automated?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34422
347
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is a JSUnit library which follows the same XUnit conventions as JUnit does for Java. This allows you to write tests in JavaScript that you can run repeatedly against your JavaScript code to tell it is still working.
 
Christian Johansen
author
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are heaps of JavaScript testing frameworks out there. The one I am currently recommending is JsTestDriver (http://code.google.com/p/js-test-driver/) which lets you automate many browsers very easily, supports most CI tools and so on. Give it a spin. There is also an introduction on my site: http://cjohansen.no/en/javascript/test_driven_javascript_done_right

For stubbing and mocking, there is also http://cjohansen.no/sinon/ which is test framework agnostic, and works very well with JsTestDriver.
 
Filipi Zimermann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys, and what about qUnit (http://docs.jquery.com/Qunit) ?
Have you already used it? Recommend? Don't recommend?

I use Jquey extensively. Should this influence in my tool choice?
 
Christian Johansen
author
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whether you use jQuery or not (or some other library for that matter) shouldn't matter to your testing tool preference. As long as jQuery is already a part of your project, you are still free to use it in your tests no matter what framework you use.

With that said, QUnit is a decent framework, but I personally find it to be slightly lacking in features. I really like high-level assertions, as I feel they make tests clearer, and failures easier to track down. QUnit only has a few assertions. But, it boils down to preference. QUnit is easy to use and has a nice browser runner, and you can even run the tests on multiple browsers simultaneously via JsTestDriver (which has a QUnit bridge).
 
Filipi Zimermann
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nice. Thanks for the answer.

I didn't know JSTestDriver.

I would ask about IDE integration but I'm seing at the JSTestDriver website that it integrates with Eclipse.
I use Aptana, probably will easily integrate there too (I had some problems to integrate some eclipse plugins in Aptana Studio once).

I'll take a deep immersion on JSTestDriver now.
Thanks again!
 
Christian Johansen
author
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No problem! While I haven't used it in Aptana myself, I know that other people have made it work. Good luck
 
Gordon Bockus
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great info. Is there a way to put JSTestDriver into command line mode where it could run in a non-browser evn? This is a concern for me when builds run on a mix of systems...some with displays available and some headless. Thanks
 
Christian Johansen
author
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gordon: Unfortunately, no, at the moment this is not possible. But I'm working on something like this, so hopefully that will be possible sometime soon. I haven't tried, but you might get this working with Rhino and env.js, which allows JavaScript on the command line to act as a browser environment, but I'm not sure if it's flexible enough to actually run this way.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic