-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathgeneral_rules.txt
More file actions
49 lines (42 loc) · 2.28 KB
/
general_rules.txt
File metadata and controls
49 lines (42 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
https://docs.python-guide.org/writing/tests/
Testing code is important
Getting used to writing testing code and running it in parallel is
considered a good habit.
Some general rules:
- A testing unit should focus on one tiny bit of functionality and
prove it correct
- Each test must be fully independant
- run alone
- run in any order
- may need to be handled by setUp() and tearDown() methods
- Tests must run fast, if they are slow, people wont use them and they
will slow down development
- heavy tests can be run in a scheduled suite
- Learn your tools and learn how to run a single test or test case. When
developing a function inside a module, run this functions tests
frequently. Ideally automatically when you save the code
- Always run the full test suite before a coding session, and run it
again after. This will give you more confidence that you did not
break anything in the rest of the code.
- It is a good idea to implement a hook that runs all tests before
pushing code to a shared repo
- If you are in the middle of a development session and have to
interrupt your work, it is a good idea to write a broken unit test
about what you want to develop next. When coming back to work there
will be a pointer of where to get back to work
- The first step when debugging code is to write a new test pinpointing
the bug. While it is not always possible to do, those bug catching
tests are among the most valuable pieces of code in a project
- Use long and descriptive names for testing functions.
test_square_of_number_2()
test_square_negative_number()
These are the function names that are displayed when a test fails
so they should be as descriptive as possible
- When something goes wrong or has to be changed, and if your code has a
good set of tests, you or other maintainers will largely rely on
the testing suite to fix the problems.
Testing code will be read as much or even more than running code.
A unit test whose purpose is unclear is not very helpful...
- Another use of the testing code is as an introduction to new
developers. Running and reading related testing code is a great
place to start. It will uncover hot spots and corner cases easily