Skip to content

Instantly share code, notes, and snippets.

@davidefella
Last active December 19, 2022 14:40
[Odoo: Testing in Odoo 13] #test #debug #unit #modules #manifest #init #singletransactioncase #transactioncase #setup #unittest #exception #running #test-enable #assertions
Source: https://www.cybrosys.com/blog/how-to-test-python-code-odoo-13
source: https://medium.com/@reedrehg/writing-tests-in-odoo-4355f33e4a36
https://www.odoo.com/it_IT/forum/help-1/question/unit-tests-coverage-in-odoo-164562
*** Pattern ***
https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html
https://medium.com/@pjbgf/title-testing-code-ocd-and-the-aaa-pattern-df453975ab80
1) Creating python files
- In order to add unit tests to our module, first of all, we have to create a subdirectory ”tests”.
- The “.py” files names inside this directory should be started with ‘test_’ otherwise it will not execute the tests.
- After that we have to import this test_custom.py file in the __init__.py
2) Creating the classes
- TransactionCase (separate transaction for each test) vs SingleTransactionCase(runs all the tests in a single transaction)
- setUp() --> is where we prepare data and variables to be used
3) Writing Test Cases
- assertEqual()
4) Testing Exceptions
- from odoo.exceptions import Warning
- self.assertRaises()
5) --test-enable -d odoo13-newco-test -i sla_customer_pause --stop-after-init
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment