Background Image
Table of Contents Table of Contents
Previous Page  391 / 478 Next Page
Information
Show Menu
Previous Page 391 / 478 Next Page
Page Background

Let Complexity Be Your Guide

I’d say the point at which isolated tests start to become worth it is to do with complexity.

The example in this book is extremely simple, so it’s not often been worth it so far. Even

in the example in this chapter, I can convince myself I didn’t really

need

to write those

isolated tests.

But once an application gains a little more complexity—if it starts growing any more

layers between views and models, if you find yourself writing helper methods, or your

own classes, then you will probably gain from writing more isolated tests.

Should You Do Both?

We already have our suite of functional tests, which will serve the purpose of telling us

if we ever make any mistakes in integrating the different parts of our code together.

Writing isolated tests can help us to drive out better design for our code, and to verify

correctness in finer detail. Would a middle layer of integration tests serve any additional

purpose?

I think the answer is potentially yes, if they can provide a faster feedback cycle, and help

you identify more clearly what integration problems you suffer from—their tracebacks

may provide you with better debug information than you would get from a functional

test, for example.

There may even be a case for building them as a separate test suite—you could have one

suite of fast, isolated unit tests that don’t even use

manage.py

, because they don’t need

any of the database cleanup and teardown that the Django test runner gives you, and

then the intermediate layer that uses Django, and finally the functional tests layer that,

say, talks to a staging server. It may be worth it if each layer delivers incremental benefits.

It’s a judgement call. I hope that, by going through this chapter, I’ve given you a feel for

what the trade-offs are.

Onwards!

We’re happy with our new version, so let’s bring them across to master:

$

git add .

$

git commit -m"add list owners via forms. more isolated tests"

$

git checkout master

$

git checkout -b master-noforms-noisolation-bak

# optional backup

$

git checkout master

$

git reset --hard more-isolation

# reset master to our branch.

In the meantime—those FTs are taking an annoyingly long time to run. I wonder if

there’s something we can do about that?

Conclusions: When to Write Isolated Versus Integrated Tests

|

363