~ubuntu-branches/ubuntu/saucy/autopilot/saucy-proposed

« back to all changes in this revision

Viewing changes to docs/tutorial/good_tests.rst

  • Committer: Package Import Robot
  • Author(s): Didier Roche
  • Date: 2013-06-07 13:33:46 UTC
  • mfrom: (57.1.1 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130607133346-42zvbl1h2k1v54ac
Tags: 1.3daily13.06.05-0ubuntu2
autopilot-touch only suggests python-ubuntu-platform-api for now.
It's not in distro and we need that requirement to be fulfilled to
have unity 7, 100 scopes and the touch stack to distro.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
Several points in this document are written with respect to the unity autopilot test suite. This is incidental, and doesn't mean that these points do not apply to other test suites!
7
7
 
 
8
.. _write-expressive-tests:
 
9
 
 
10
Write Expressive Tests
 
11
++++++++++++++++++++++
 
12
 
 
13
Unit tests are often used as a reference for how your public API should be used. Functional (Autopilot) tests are no different: they can be used to figure out how your application should work from a functional standpoint. However, this only works if your tests are written in a clear, concise, and most importantly expressive style. There are many things you can do to make your tests easier to read:
 
14
 
 
15
**Pick Good Test Case Class Names**
 
16
 
 
17
Pick a name that encapsulates all the tests in the class, but is as specific as possible. If necessary, break your tests into several classes, so your class names can be more specific. This is important because when a test fails, the test id is the primary means of identifying the failure. The more descriptive the test id is, the easier it is to find the fault and fix the test.
 
18
 
 
19
**Pick Good Test Case Method Names**
 
20
 
 
21
Similar to picking good test case class names, picking good method names makes your test id more descriptive. We recommend writing very long test method names, for example:
 
22
 
 
23
.. code-block:: python
 
24
 
 
25
    # bad example:
 
26
    def test_save_dialog(self):
 
27
        # test goes here
 
28
 
 
29
    # better example:
 
30
    def test_save_dialog_can_cancel(self):
 
31
        # test goes here
 
32
 
 
33
    # best example:
 
34
    def test_save_dialog_cancels_on_escape_key(self):
 
35
        # test goes here
 
36
 
 
37
**Write Docstrings**
 
38
 
 
39
You should write docstrings for your tests. Often the test method is enough to describe what the test does, but an English description is still useful when reading the test code. For example:
 
40
 
 
41
.. code-block:: python
 
42
 
 
43
    def test_save_dialog_cancels_on_escape_key(self):
 
44
        """The Save dialog box must cancel when the escape key is pressed."""
 
45
 
 
46
We recommend following :pep:`257` when writing all docstrings.
 
47
 
 
48
 
8
49
Test One Thing Only
9
50
+++++++++++++++++++
10
51
 
120
161
Test docstrings are used to communicate to other developers what the test is supposed to be testing. Test Docstrings must:
121
162
 
122
163
 1. Conform to `PEP8 <http://www.python.org/dev/peps/pep-0008/>`_ and `PEP257 <http://www.python.org/dev/peps/pep-0257/>`_ guidelines.
123
 
 2. Avoid words like "should" in favour of stronger words like "must".
 
164
 2. Avoid words like "should" in favor of stronger words like "must".
124
165
 3. Contain a one-line summary of the test.
125
166
 
126
167
Additionally, they should: