I would like to try and implement some TDD in our web applications to reduce regressions and improve release quality, but I'm not convinced at how well automated testing can perform with something as fluffy as web applications.

I've read about and tried TDD and unit testing, but the examples are 'solid' and rather simple functionalities like currency converters, and so on.

Are there any resources that can help with unit testing content management and publication systems? How about unit testing a shopping cart/store (physical and online products)? AJAX?

Googling for "Web Test Driven Development" just gets me old articles from several years ago either covering the same examples of calculator-like function or discussions about why TDD is better than anything (without any examples).

  • 1
    the tools available will depend on the language. which language(s) are you using?
    – Alb
    Commented Mar 21, 2011 at 23:19
  • I realise that - but I was looking more for discussion articles and essays rather than specific tools. I know what tools are available, but would like to learn how best to use them for front-end driven applications.
    – HorusKol
    Commented Mar 21, 2011 at 23:25

4 Answers 4


Big disclaimer: I've not built any web applications nor have I tested any web applications. The following are just tidbits of information I've absorbed in my random walks within the information sphere.

Construct your web application in such a way so as to be able to test business rules in isolation. If you find yourself testing business rules through the user interface then it might be time to think about redesigning.

When it comes to testing the UI, replace your business rules with mock implementations that respond in predictable ways.

The above two rules are taken from Bob Martin's talk at RailsConf 2010. The talk isn't about TDD and the section where he mentions testing is short and somewhere in the middle.

There are tools like JsUnit, JSSpec, YUI Test for testing JavaScript and Selenium and Watir for testing UI.

The Pragmatic Bookshelf have a few books covering testing of web applications. A list of books tagged with Testing is at http://www.pragprog.com/categories/design. The Pragmatic Bookshelf web app testing books are mainly focussed around Ruby and Rails but should be generically applicable.

  • One major issue with web design is CSS testing - a new CSS rule may have unintended consequences, but only on a page with specific content... Can you unit test that?
    – HorusKol
    Commented Mar 22, 2011 at 1:09
  • Good question. I would suggest this is part of your UI testing. You develop your tests to include the various page contents you expect (and a few you don't expect) and write your acceptances appropriately. Then, when you introduce new CSS rules, your UI testing should highlight any regressions. It maybe that this process is too time consuming and you may be better served by just having someone do QA testing on the site and reporting problems. Commented Mar 22, 2011 at 2:01

Test-Driven JavaScript Development is a really nice book from Christian Johansen, the developer behind Sinon.js and Buster.js, which covers subjects such as (taken from the website):

  • Understanding unit testing and TDD
  • Choosing the right unit testing framework
  • Building cleaner APIs, modularized and robust JavaScript
  • Continuously improving code through refactoring
  • Five practical TDD sessions: Ajax, DOM manipulation, Node.js and more
  • Test-driven tour to JavaScript for developers not familiar with the language

Currently we use Sinon.js with Mocha, but ready to switch to Buster.js, since its features are really neat!


On a project I worked on recently the lead developer had decided to use Unity so that mocking and TDD were simplified in a large web application - I reckon Unity use will often be accompanied by TDD is a web application.

Investigating unit testing CMS is likely to lead to a dead end because there simply isn't a reasonable thing to mock. I don't see what can be tested without mocking the http traffic to the pages - and at that point the test has little value.

I reckon a useful rule of thumb with web applications is if it can use a mock to reduce complexity then it can probably be unit tested.

So in a web application you can mock your database to unit test different parts of your data access layer or model; you can mock user input to unit test the view or UI and so on.


I've written a book on TDD for web development with Python + Django. it covers TDD, both with end-to-end / functional tests (selenium) and lower-level "unit" tests. I also cover modern dev practices like how to integrate git into your workflow, how to deploy to a server and automate and test that, continuous integration, mocks and test isolation, and lots more:


(or http://shop.oreilly.com/product/0636920051091.do)

  • The link is broken Commented Jun 26, 2018 at 9:26

Not the answer you're looking for? Browse other questions tagged or ask your own question.