How to do it...

Follow these steps to add Python test cases in the my_library module:

  1. Add a new file, tests/__init__.py, as follows:
from . import test_book_state
  1. Add a tests/test_book_state.py file, and add the test case, as follows:
from odoo.tests.common import TransactionCase

class TestBookState(TransactionCase):

def setUp(self, *args, **kwargs):
super(TestBookState, self).setUp(*args, **kwargs)
self.test_book = self.env['library.book'].create({'name': 'Book 1'})

def test_button_available(self):
"""Make available button"""
self.test_book.make_available()
self.assertEqual(self.test_book.state, 'available',
'Book state should changed to available')

def test_button_lost(self):
"""Make lost button"""
self.test_book.make_lost()
self.assertEqual(self.test_book.state, 'lost',
'Book state should changed to lost')

In order to run the test cases, start the Odoo server with the following option:

./odoo-bin -c server.conf -i my_library --test-enable

Now, check the server log. You will find the following logs if our test cases ran successfully:

... INFO test odoo.modules.module: odoo.addons.my_library.tests.test_book_state running tests. 
... INFO test odoo.addons.my_library.tests.test_book_state: test_button_available (odoo.addons.my_library.tests.test_book_state.TestWizard)
... INFO test odoo.addons.my_library.tests.test_book_state: ` Make available button
... INFO test odoo.addons.my_library.tests.test_book_state: test_button_lost (odoo.addons.my_library.tests.test_book_state.TestWizard)
... INFO test odoo.addons.my_library.tests.test_book_state: ` Make lost button
... INFO test odoo.addons.my_library.tests.test_book_state: Ran 2 test
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset