From 664f5a2910de2eb7cd1edf5930b47da769dd2d6d Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Sat, 10 Mar 2012 14:59:01 -0800 Subject: [PATCH] Update static version. --- static/index.html | 53 ++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 21 deletions(-) diff --git a/static/index.html b/static/index.html index 91f3e5d..ec17d19 100644 --- a/static/index.html +++ b/static/index.html @@ -95,16 +95,6 @@

carl@oddbird.net

github.com/carljm/django-testing-slides

github.com/carljm/django-testing-slides/code

-
-

The plan

- -
    -
  • Test discovery
  • -
  • Testing models
  • -
  • Testing views
  • -
  • Testing docs
  • -
-

Let's start a project.

@@ -151,7 +141,7 @@

tests/__init__.py

Django made me do it. (Or worse yet, "import *".)

-

Django's test runner

+

Django's test discovery

  • Wastes my time with tests I don't care about.
  • @@ -167,7 +157,7 @@

    It's easy to change.

    • unittest2 discovery
    • -
    • TEST_RUNNER
    • +
    • TEST_RUNNER setting
    @@ -207,7 +197,7 @@

    settings.py

    \o/

      -
    • Discovers tests wherever you put them.
    • +
    • Discovers tests wherever you want them.
    • Doesn't run tests from external apps by default.
    • Flexible specification of specific tests to run: Python dotted path to test module, not Django app label.
    • @@ -233,7 +223,7 @@

      Types of test

      Go see the video of Gary's "Fast test, slow test" talk.

-
+

Unit tests

    @@ -243,12 +233,14 @@

    Unit tests

  • Help you structure your code better.

-
+

Integration tests

  • Test that the whole integrated system works; catch regressions.

  • -
  • Slow (just write a few, test the edge cases with unit tests).

  • +
  • Slow.

  • +
  • Less useful failures.

  • +
  • Write fewer.

@@ -260,12 +252,30 @@

The database makes your tests slow.

  • Try to write tests that don't hit it at all.
  • +
  • Separate db-independent model-layer functionality from db-dependent +functionality.
  • But you'll still have a lot of tests that do.
  • +
  • Mocking the database usually isn't worth it.
- - -

The DB is pretty core to most web apps; mocking it makes your tests fast, but I don't think it's worth it.

-
+
+
+
class Thing(models.Model):
+  def frobnicate(self):
+    """Frobnicate and save the thing."""
+    # ... do something complicated
+    self.save()
+
+
def frobnicate_thing(thing):
+  # ... do something complicated
+  return thing
+
+
+class Thing(models.Model):
+  def frobnicate(self):
+    """Frobnicate and save the thing."""
+    frobnicate_thing(self)
+    self.save()
+

django.test.TestCase

    @@ -276,7 +286,7 @@

    django.test.TestCase

    Django tries to make them fast...

-
+

TransactionTestCase

    @@ -537,6 +547,7 @@

    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.