At the moment I'm working on a JS library for a webservice, you can pare 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
At the moment I'm working on a JS library for a webservice, you can pare 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
Share Improve this question edited Mar 5, 2011 at 12:33 Sachin Shanbhag 55.5k11 gold badges91 silver badges103 bronze badges asked Mar 5, 2011 at 12:27 ChielusChielus 6328 silver badges19 bronze badges 2- 1 Have you had a look at Jasmine ( pivotal.github./jasmine ) yet? – polarblau 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. – Chielus Commented Mar 7, 2011 at 8:44
2 Answers
Reset to default 5Javascript 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 ponents using TDD and got clear desing and more pact code!
- unit test framework of choice is qUnit. It is very easy to start with testing.
- 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 :)
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 es 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.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745421602a4626988.html
评论列表(0条)