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).
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.
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.
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.
- Understanding unit testing and TDD
- Choosing the right unit testing framework
- Continuously improving code through refactoring
- Five practical TDD sessions: Ajax, DOM manipulation, Node.js and more
Currently we use Sinon.js with Mocha, but ready to switch to Buster.js, since its features are really neat!
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: