Resources for Test Driven Development in Web Applications?

by HorusKol   Last Updated June 26, 2018 14:05 PM

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

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 The Pragmatic Bookshelf web app testing books are mainly focussed around Ruby and Rails but should be generically applicable.

Anthony Cramp
Anthony Cramp
March 22, 2011 00:14 AM

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.

March 22, 2011 00:50 AM

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!

October 08, 2012 18:49 PM

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:

April 01, 2013 13:50 PM

Related Questions

What is the best method for testing a web app?

Updated November 23, 2018 13:05 PM

Is QA/QC more related to proprietary softwares?

Updated January 22, 2019 22:05 PM

In c# how do people make complex functions

Updated October 05, 2016 09:02 AM