aboutsummaryrefslogtreecommitdiff
path: root/docs/source/best_practices.md
blob: ced3de5669391b2c8f47435d516c5e5409d60a30 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Best Practices

Here we collection tips and techniques for keeping your tests maintainable and
avoiding common pitfalls.

### Put each suite of tests in its own sub-package

It's recommended to put a given suite of unit tests in their own sub-package
(directory with a BUILD file). This is because the names of your test functions
become target names in the BUILD file, which makes it easier to create name
conflicts. By moving them into their own package, you don't have to worry about
unit test function names in one `.bzl` file conflicting with names in another.

### Give test functions private names

It's recommended to give test functions private names, i.e. start with a leading
underscore. This is because if you forget to add a test to the list of tests (an
easy mistake to make in a file with many tests), the test won't run, and it'll
appear as if everything is OK. By using a leading underscore, tools like
buildifier can detect the unused private function and will warn you that it's
unused, preventing you from accidentally forgetting it.