How it works...

We create a Python subpackage in our module called tests and add a test module with a name starting with test_. This is the convention used by Odoo for test discovery.

In this file, we import the base test class, TransactionCase from odoo.tests.common. This class extends the unittest.TestCase class from the Python standard library to make it suitable for use in Odoo by overloading the setUp() and tearDown() methods of unittest.TestCase:

  • The setUp() method initializes the self.env attribute that you can use to perform the usual operations (refer to the recipes in Chapter 6, Basic Server-Side Development)
  • The tearDown() method rolls back the database transaction so that the tests are run in insulation
If your test case redefines ...

Get Odoo 11 Development Cookbook - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.