Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 7eb4827dc7
Fetching contributors…

Cannot retrieve contributors at this time

34 lines (22 sloc) 0.872 kB

<!SLIDE incremental>

What type of test to write?

  • Write system tests for your views.

  • 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 at most 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.