Adding tests to an uncovered application - Zach Smith

Tags: django, djangocon

http://instagr.am originally started out as burbn, some sort of html5 version of foursquare. But it got killed and became instragr.am. Any tests they would have put into burbn would have been effectively wasted. It is OK not to test stuff when you’re still figuring things out.

A couple of reasons to do add tests:

  • If it saves time.

  • If your team needs it.

  • Things really really have to work.

He uses lettuce for the acceptance tests. Lettuce uses “gherkin syntax”: scenarios are described with given/when/then sentences. GIVEN the state of the system WHEN an action is taken THEN the result should be xyz.

Scenarios are grouped into features. You test all the scenarios to make sure that the feature works.

With a scenario like “WHEN I submit a vote THEN …”, “I submit a vote” needs to be registered as a “step” in your test setup. The system is pretty straightforward (note: he showed a couple of examples that looked pretty clear).

He used unclebob which helps running your nose django tests. It lets you split your tests in subdirectories for acceptation, functional and unit tests.

He also used sure, which provides extra test assertions. Very handy for functional tests.

For unit tests, mock is a handy library to mock things (note: yes, very handy). But there are a couple of cases where mock conflics with django, especially in the model layer were quite some halfway-magic python stuff happens.

Kleine camping in Westervelde
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):