testing: More restructuring for the Nose source
[swc-testing-nose.git] / testing / nose / instructor.md
1 # Test locations
2
3 Nose [looks in the usual places][finding-tests].
4
5 * Nose tests live in files matching `[Tt]est[-_]`
6 * Nose can find `unittest.TestCase` subclasses.
7 * Nose also finds functions matching the `testMatch` regular
8   expression.
9
10 # Test syntax
11
12 Nose tests use assertions
13
14 ```python
15 assert should_be_true()
16 assert not should_not_be_true()
17 ```
18
19 There are lots of assertion helpers in `nose.tools`
20 ([docs][nose-assertions]), which [exports][nose-assertion-export] the
21 [unittest assertions][unittest-assertions] in [PEP 8][pep8] syntax
22 (`assert_equal` rather than `assertEqual`).  There are more assertion
23 helpers in `numpy.testing` ([docs][NumPy-assertions]) for arrays and
24 numerical comparisons.
25
26 # Basic nose
27
28 Writing tests for `mean()`:
29
30 * Basic implementation: [mean.py][basic-mean]
31 * Internal exception catching: [mean.py][exception-mean]
32 * Embedded tests: [mean.py][embedded-test-mean]
33 * Independent tests: [test_mean.py][test-mean]
34
35 # Test-driven development
36
37 We have [a Fibonacci example][fibonacci] with a series of increasingly
38 detailed tests and implementations.
39
40 # Quality assurance
41
42 Can you think of other tests to make for the Fibonacci function?  I
43 promise there are at least two.
44
45 Implement one new test in `test_fibonacci.py`, run `nosetests`, and if
46 it fails, implement a more robust function for that case.
47
48
49 [finding-tests]: https://nose.readthedocs.org/en/latest/finding_tests.html
50 [nose-assertions]: https://nose.readthedocs.org/en/latest/testing_tools.html#testing-tools
51 [nose-assertion-export]: https://github.com/nose-devs/nose/blob/master/nose/tools/trivial.py#L33
52 [unittest-assertions]: http://docs.python.org/2/library/unittest.html#assert-methods
53 [pep8]: http://www.python.org/dev/peps/pep-0008/
54 [NumPy-assertions]: http://docs.scipy.org/doc/numpy/reference/routines.testing.html#asserts
55 [basic-mean]: exercises/mean/basic/mean.py
56 [exception-mean]: exercises/mean/exceptions/mean.py
57 [embedded-test-mean]: exercises/embedded-tests/mean.py
58 [test-mean]: exercises/test_mean.py
59 [fibonacci]: exercises/fibonacci