Search code examples
javascriptunit-testingqunit

How I should organize QUnit testing?


I have big Web app (Backbone.js, Marionette, Require.js ...). Now, I need to make unit tests for my app. I've learned QUnit library yesterday. I was very easy with simple functions. But now, if I want to test my real app, I meet a lot of troubles and questions.
1. How organize file's structure
2. Do I sholud test only events or functions?
3. Can you give me examples of unit test for Backbone, Require js code with QUnit.
Thank you very much.


Solution

  • you are gonna have to replicate your common code in few files, like appilcation start and everything, then inlcude these files in each of the unit test html files. Then you can write tests for each individual views/folders. You can use something like Balnket.js for checking your coverage.

    Remember few ground rules:

    1. Test one function at time, stub(with something like sinon.js) external code being called from this function).
    2. There should be no server calls initiated from your test page, they should be faked.