Adding automated tests
Programming best practices include having automated tests for your code. This is even more important for dynamic languages such as Python—since there is no compilation step, you can't be sure there are no syntactic errors until the code is actually run by the interpreter. A good editor can help us spot these problems ahead of time, but can't help us ensure the code performs as intended, like automated tests can.
Note
Changed in Odoo 12
In previous versions, Odoo also used tests described using YAML data files. YAML data-file support was removed in Odoo 12, so this type of test is not available anymore.
The test-driven development (TDD) method states that we should write tests up front, check that they fail, then develop the code that, in the end, should pass the tests. Inspired by this approach, we will add our module tests now, before we add the actual features:
- The test code files should have a name starting with
test_
and should be imported fromtests/__init__.py
. But...