Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
36 lines (23 sloc) 928 Bytes

<!SLIDE incremental>

What type of test to write?

  • Write system tests for your views.

  • Write Selenium tests for Ajax, other JS/server interactions.

  • Write unit tests for everything else (not strict).

  • Test each case (code branch) where it occurs.

  • One assert/action per test case method.

.notes Very rough guidelines; what works for me. Not strict; e.g. tests for a ModelForm don't mock the model.


@@@ python
def add_quote(request):
    if request.method == "POST":
        form = QuoteForm(request.POST)
        if form.is_valid():
            return redirect("quote_list")
        form = QuoteForm()

    return TemplateResponse(
        {"form": form},

.notes This view should have 3 tests. Model/form special cases should be unit tested. And views shouldn't get much more complex.

Jump to Line
Something went wrong with that request. Please try again.