Testing your Backbone code will let you write better apps, faster. This series will show you how. I’ll cover unit and functional testing, and techniques to test your app without a live backend/API.
Why should I care about testing my Backbone code?
Let me give you the typical pro-testing before and after:
It's Friday at 18.46. Your app isn't working on IE again. You fix and deploy, and realise you've pushed a one character typo. Meeting friends in the pub? Nope.
Flash to a cheesy silver bullet comparison:
IE didn't have
Array#indexOf but your tests alerted you before deploy. The release was great: no surprise, you already knew it worked from your happily blinking test suites. Desk beer!
Sounds nice! However, silver bullets belong in vampire stories. Every programming practice has costs along with benefits, testing is no exception. So we have an additional story to consider:
It's Friday at 18.46. Your Selenium suite takes 28 minutes to run, and your 96% code coverage unit test suite had to be rewritten due to product changes. You need to release to make users happy, but all your time was spent fixing tests.
Testing is not the goal - releasing a great Backbone app for your users is! I’ll be highlighting techniques to keep your tests from become fragile and costly to maintain.
The articles in the series will be:
- Testing Backbone views
- Testing Backbone models
- Asynchronous tests
- Creating a mocked server for Backbone apps
- Advanced Backbone views - easy testing with view models
- Functional testing for Backbone
This series is drawn from the methods I've found most effective while developing a number of products with Backbone - an analytics dashboard for Skimlinks, numerous real time games for Picklive, a machine learning Twitter client and Chrome extensions.
What will I learn?
By the end of the series you'll be able to:
- write well tested Backbone models, collections, routers and views
- test all the fiddly bits - functional tests, AJAX and asynchronous tests
- create demo ‘servers’ to run your app without a live backend.
- have some principles to decide when testing is worth it
If you're in the UK, you might like the class I've run before and will run again in the future at General Assembly London, Building Web Apps with Backbone.js. It'll take you through Backbone.js from the basics, and work through a case study of converting a legacy jQuery app into a single-page Backbone app.
Thanks for reading, please say hi if you've any questions - @timruffles.
Any comments? Please tweet @timruffles