10

I spend a lot of time working in javascript of late. I have not found a way that seems to work well for testing javascript. This in the past hasn't been a problem for me since most of the websites I worked on had very little javascript in them. I now have a new website that makes extensive use of jQuery I would like to build unit tests for most of the system.

My problems are this.

  • Most of the functions make changes to the DOM in some way.
  • Most of the functions request data from the web server as well and require a session on the service to get results back.

I would like to run the test from either a command line or a test running harness rather then in a browser.

Any help or articles I should be reading would be helpful.

gnat
20.5k29 gold badges117 silver badges308 bronze badges
asked Mar 2, 2011 at 18:54
1
  • Have a look at JSTestDriver, written by Misko Hevery, who writes a lot of great articles on testability in general. Commented Mar 2, 2011 at 19:57

2 Answers 2

3

Maybe QUnit could help you. It is the official test suite of the jQuery project. As described in the documentation, tests can also be run outside of a browser (with Rhino for instance).

answered Mar 2, 2011 at 19:24
1

Because of the interactive nature of Javascript, it's hard to write unit-tests to anything but libraries. To test interactions, we use Selenium which allows you to record interactions and check for expected outcome (such as a DIV appearing or a value changing). Tests can be grouped into suites and ran automatically.

Selenium tests can also be run on the server without a browser with some additional setup.

answered Mar 2, 2011 at 20:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.