Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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).

share|improve this question

closed as not constructive by gnat, Martijn Pieters, Kilian Foth, thorsten müller, ChrisF Apr 2 '13 at 21:18

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

the tools available will depend on the language. which language(s) are you using? –  Alb Mar 21 '11 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 Mar 21 '11 at 23:25

4 Answers 4

up vote 2 down vote accepted

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.

share|improve this answer
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 Mar 22 '11 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. –  Anthony Cramp Mar 22 '11 at 2:01

I've written a tutorial for TDD and web development with Python and Django. It includes using Selenium for front-end / UI testing, so the techniques are applicable if you want to move to a more rich UI, javascript etc.


There's also a book in the works...

share|improve this answer

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!

share|improve this answer

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.

share|improve this answer

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