Adding unit tests
Python tests are added to addon modules by using a tests/
subdirectory. The test runner will automatically discover tests in the subdirectories with that particular name.
The tests on our todo_wizard
addon will be in a tests/test_wizard.py
file. We will need to add the tests/__init__.py
file:
from . import test_wizard
And this would be the basic skeleton for the tests/test_wizard.py
:
# -*- coding: utf-8 -*- from odoo.tests.common import TransactionCase class TestWizard(TransactionCase): def setUp(self, *args, **kwargs): super(TestWizard, self).setUp(*args, **kwargs) # Add test setup code here... def test_populate_tasks(self): "Populate tasks buttons should add two tasks" # Add test code
Odoo provides a few classes to use for tests. The TransactionCase
tests uses a different transaction for each test, that is automatically rolled back at the end. We can also...