Search code examples
jqueryunit-testingweb-applicationsqunit

QUnit on a web application?


I'm mainly a jquery dev, and i work on a struts 2/spring/hibernate form application. I don't develop a plugin or anything like that, it's just plain jquery code to show/hide things, validate forms, submit using ajax, do some calculations and so on. I don't understand what i should test exactly (most of my code is like, click on a checkbox to show an associated div and such), nor how should i test it (like ajax submissions).

I read some tutos on the subject, but it doesn't seem to fit my needs (seems like it's meant to be used when you develop standalone js code, like jquery is), or if it does, i don't understand how. But i really want to unit test, since i spend days testing those features manually (are div correctly displayed when you click on checkbox x ? are fields being validated on the fly ? etc), doing exactly the same things over and over on multiples forms because of code regression, and probably missing stuff in the process.

Help will be really appreciated ! Thanks guys


Solution

  • If your js files mainly consist of DOM manipulations, qunit won't be a good fit. Instead, use a combination of selenium and jenkins if you're into TDD.

    QUnit is helpful if you have functions that return values, or if you use an JavaScript MVC framework like Backbone.js. You can test the Model part of it.

    See Testing Javascript that Manipulates the DOM