10

At the moment I'm working on a JS library for a webservice, you can compare it with Twitter Anywhere. Now i want to make it more test-driven. It's not easy to test because it has to work on every site that wants to make use of it, and of course with every browser.

How can i test the library efficiently?

All the API requests and responses are in JSON, is there a good way to test these calls?

I know about Cucumber and js-test-driver.

Greetings, Chielus

2
  • 1
    Have you had a look at Jasmine ( pivotal.github.com/jasmine ) yet? Commented Mar 5, 2011 at 15:45
  • I don't think i can do BDD, because it's a library that has to work with all kinds of sites. Commented Mar 7, 2011 at 8:44

2 Answers 2

5

Javascript language is dynamic by nature, so it is really test-driven friendly. I've recently got a little experience with javascript testing. I've rewrote major javascript components using TDD and got clear desing and more compact code!

  1. unit test framework of choice is qUnit. It is very easy to start with testing.
  2. functional test framework of choise is funcunit.

I did a blog post of testing REST api with FuncUnit here.

If you need some examples of tests and implementation, you can check my github repository.

Don't ask questions, just start testing :)

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for your blog post, very interesting to see an example (which is so close to my usecase!)
2

If you know about jsTestDriver I think you've already found a good solution?

You can use it to automatically launch your tests in multiple browsers and return success or failure.

This sets it apart from other tools that use headless browsers, as with jsTestDriver you're running your tests in real browsers, which seems to meet your requirements.

jsTestDriver comes with its own limited assertion framework but you can plug others into it including QUnit, YUI and Jasmine.

You said above in relation to Jasmine, "I don't think i can do BDD, because it's a library that has to work with all kinds of sites.". I'm not sure what you mean by this?

Jasmine provides all the assertions to let you do the same tests as QUnit. It also lets you 'spy' on Ajax callbacks, intercept the JSON to examine or even alter it, then pass it on to your default callback. With this you could check the JSON response then check again when your UI has reacted to it in the right way.

Comments

Your Answer

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.