Merge lp:~jtv/launchpad/decruft-test-template into lp:launchpad

Proposed by Jeroen T. Vermeulen
Status: Merged
Approved by: Jeroen T. Vermeulen
Approved revision: no longer in the source branch.
Merged at revision: 11145
Proposed branch: lp:~jtv/launchpad/decruft-test-template
Merge into: lp:launchpad
Diff against target: 28 lines (+14/-4)
1 file modified
standard_test_template.py (+14/-4)
To merge this branch: bzr merge lp:~jtv/launchpad/decruft-test-template
Reviewer Review Type Date Requested Status
Francis J. Lacoste (community) Approve
Launchpad code reviewers code Pending
Review via email: mp+30083@code.launchpad.net

Commit message

Update sample unit test file.

Description of the change

= Decruft standard test template =

This is an update I'd like for the sample unit-test file we provide in the project's top-level directory.

The boilerplate at the bottom of the test is no longer needed, as far as I know. If this is correct, I'd also like to remove it from as many existing tests as I reasonably can.

I also documented some guidelines and typical steps, such as the layer. I don't know how it is for others but I'm generally too lazy to remember what layers there are and where to import them from, so I included that information.

Is this too much? I don't want engineers to have to spend more time deleting text from the sample than they would otherwise spend putting up scaffolding.

The new file is lint-free. This is why the "XXX: Sample test class" comment is inside the test class, not above it: otherwise "make lint" would expect a double blank line between the comment and the class definition.

The new sample test also actually passes. Perhaps it would be worthwhile to make it part of the test suite so that we can be sure it doesn't fall out of date.

Jeroen

To post a comment you must log in.
Revision history for this message
Francis J. Lacoste (flacoste) wrote :

I think this is all good. Deleting text is easy, more than adding it, so I'm all in favor of it. You might want to get a second opinion though.

review: Approve
Revision history for this message
Jeroen T. Vermeulen (jtv) wrote :

Merci!

Actually, you _are_ the second opinion. :-) I first sanity-checked the idea of removing the boilerplate with lifeless.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'standard_test_template.py'
2--- standard_test_template.py 2010-01-12 03:07:09 +0000
3+++ standard_test_template.py 2010-07-16 10:37:43 +0000
4@@ -5,10 +5,20 @@
5
6 __metaclass__ = type
7
8-import unittest
9-
10+from canonical.testing import DatabaseFunctionalLayer
11 from lp.testing import TestCase
12
13
14-def test_suite():
15- return unittest.TestLoader().loadTestsFromName(__name__)
16+class TestSomething(TestCase):
17+ # XXX: Sample test class. Replace with your own test class(es).
18+
19+ # XXX: Optional layer--see lib/canonical/testing/layers.py
20+ # Get the simplest layer that your test will work on, or if you
21+ # don't even use the database, don't set it at all.
22+ layer = DatabaseFunctionalLayer
23+
24+ # XXX: Sample test. Replace with your own test methods.
25+ def test_baseline(self):
26+
27+ # XXX: Assertions take expected value first, actual value second.
28+ self.assertEqual(4, 2 + 2)