Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More stuff.

  • Loading branch information...
commit 7eb4827dc773c867fb6af42cafe223a5639b78dc 1 parent 4017e50
@carljm authored
View
2  code/runner.py
@@ -5,9 +5,9 @@
"""
from django.conf import settings
+from django.test import TestCase
from django.test.simple import DjangoTestSuiteRunner, reorder_suite
from django.utils.importlib import import_module
-from django.utils.unittest import TestCase
from django.utils.unittest.loader import defaultTestLoader
View
31 levels/10_intro.md
@@ -0,0 +1,31 @@
+<!SLIDE>
+
+# Types of test #
+
+* unit
+
+* system / integration / functional
+
+.notes Go see the video of Gary's "Fast test, slow test" talk.
+
+
+<!SLIDE>
+
+# Unit tests #
+
+* Test one unit of code (a function or method) in something approaching
+ isolation.
+
+* Fast, focused (useful failures).
+
+* Help you structure your code better.
+
+<!SLIDE>
+
+# Integration tests #
+
+* Test that the whole integrated system works; catch regressions.
+
+* Slow (just write a few, test the edge cases with unit tests).
+
+.notes Summary: both are useful, write more unit tests.
View
25 models/30_no_database.md
@@ -0,0 +1,25 @@
+<!SLIDE incremental>
+
+# Imposing no-DB discipline. #
+
+* For certain test cases.
+
+<!SLIDE>
+
+ @@@ python
+ from django.utils.unittest import TestCase
+
+ import mock
+
+ cursor_wrapper = mock.Mock()
+ cursor_wrapper.side_effect = \
+ RuntimeError("No touching the database!")
+
+
+ @mock.patch(
+ "django.db.backends.util.CursorWrapper",
+ cursor_wrapper)
+ class NoDBTestCase(TestCase):
+ """Will blow up if you database."""
+
+.notes django.utils.unittest.TestCase vs django.test.TestCase. Latter's assertions mostly useful with the DB, but either way works.
View
1  showoff.json
@@ -3,6 +3,7 @@
"sections": [
{"section":"title"},
{"section":"whichtests"},
+ {"section": "levels"},
{"section":"models"},
{"section":"views"},
{"section":"doctests"},
View
2  views/20_unit.md
@@ -43,5 +43,3 @@ hard to maintain and debug.
* I rarely unit test views.
* I write less view code, and cover it via functional tests.
-
-* Functional tests are slower, but catch more bugs.
View
6 views/30_functional.md → views/30_system.md
@@ -1,6 +1,6 @@
<!SLIDE>
-# Functional testing views #
+# Integration testing views #
<!SLIDE antipattern>
@@ -55,11 +55,11 @@
## WebTest > django.test.Client ##
-* Tests are easier and faster to write.
+* System tests are easier and faster to write.
* Tests give you more confidence that the view works.
* (django-webtest provides integration.)
-.notes Django test client is in the "sour spot" - not a unit test, not a full functional test.
+.notes Django test client is in the "sour spot" - not a unit test, not a full system test. Could gain these features.
<!SLIDE>
View
33 views/50_guideline.md
@@ -0,0 +1,33 @@
+<!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.
+
+
+<!SLIDE>
+
+ @@@ python
+ def add_quote(request):
+ if request.method == "POST":
+ form = QuoteForm(request.POST)
+ if form.is_valid():
+ return redirect("quote_list")
+ else:
+ form = QuoteForm()
+
+ return TemplateResponse(
+ request,
+ "add_quote.html",
+ {"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.
View
2  whichtests/10_not_created_equal.md
@@ -21,6 +21,8 @@ But 412 tests? 14 extra seconds?
## I'll never get those 14 seconds back. ##
+.notes Does anyone still need convincing that fast test suites matter?
+
<!SLIDE>
## Not all apps are created equal. ##
View
3  whichtests/30_problem.md
@@ -3,7 +3,8 @@
# Django's test runner #
* Wastes my time with tests I don't care about.
-* Requires tests to be in a single module.
+* Requires app tests to be in a single module (resulting in boilerplate
+ imports).
* Forces intermingling of tests and non-test code.
.notes But there's good news...
View
4 whichtests/40_solution.md
@@ -27,7 +27,7 @@
top_level_dir=settings.BASE_PATH,
)
- return reorder_suite(suite, (TestCase,))
+ return reorder_suite(suite, (TestCase, TransactionTestCase))
.notes (Enhanced version in the code online with the slides.)
@@ -59,3 +59,5 @@
# Maybe in 1.5? #
* https://code.djangoproject.com/ticket/17365
+
+.notes django-nose is good too, but this could actually go in Django.
Please sign in to comment.
Something went wrong with that request. Please try again.