3. ● Avoid regression with new development
● Miss time to write your own unit tests
Why testing your code ?
4. ● Meaningful for end users
● End user manage the business part
and you handle the techy one
Why an integration test tool ?
5. ● Tests don’t need to be changed after a smallest
change in a view
● Creates server Odoo python code
● Use of our CI tool:
○ Runbot
○ Odoo.sh dev environment
Yet another custom Odoo tool
6. Our tool: an Odoo module
● Module Available on
https://github.com/odoo/ps-runbot-testing, for version 10.0,
11.0, 12.0, 13.0
● Add the repository to your addons path
● Add it on your custom runbot environment or Odoo.sh or
locally
● Make sure runbot_testing_recording is installed
● Warning:
○ use it only on a testing environment
○ Does not cover use cases that uses controller (website)
12. Add the custom code to the module you want to test using
the unit test framework of Odoo
# -*- coding: utf-8 -*-
from odoo.tests import common
class DoMyTest(common.TransactionCase):
def test_do_my_test(self):
'''
here is a description of my test
'''
uid = self.env.ref('base.user_admin').id
record = self.env['sale.order'].with_context({
'lang': 'en_US',
'search_default_my_quotation': 1,
'tz': 'Europe/Brussels',
'uid': uid
13. - The module tries to create external id dynamically
- When referencing other records in method like create
or write, the module tries to find the external id or the
smallest link to a record previously used
- A manual pass is required to fix the unfound ids, and to
create the actual tests to be made within the recorded
business flow
14. # TODO: Check or Find record_ids link (external id or otherwise)
record_ids = [
10,
]
active_id =
self.env.ref('sale_management.hereismytest_sale_advance_payment_inv_4').id
active_ids = [
self.env.ref('sale_management.hereismytest_sale_advance_payment_inv_4').id,
]
uid = self.env.ref('base.user_admin').id
self.env['account.move].browse(record_ids).with_context({
'active_id': active_id,
'active_ids': active_ids,
'active_model': 'sale.advance.payment.inv',
'type': 'out_invoice',
'uid': uid
}).with_user(uid).action_invoice_open()
'''TODO: DO A TEST HERE:
Here check amount due on invoice is 160 dollars
'''
● Fix some
references to
something that
can be
reproduce based
on a record
created earlier
● Add tests to
match with
textual
description
15. ● Make sure the integrated
test passes a fresh install
with --test-enable on your CI
tool such as the runbot
● Use those test to make sure
you avoid regression in
future development
18. Conclusions
● Use the unit test to test server side integration
tests
● Write a 1000 lines of code test in a few hours
● Involve end user in your testing process
● Ensure robustness for continuous development as
well as migration of custom code