December 2018
Beginner to intermediate
404 pages
10h 14m
English
Sometimes, we need our tests to check whether an exception was generated. A common case is testing whether some validations is being done correctly.
In our case, the wizard does some validations we can test. For example, we can test that an empty body message raises an error. To check whether an exception is raised, we place the corresponding code inside a with self.assertRaises() block.
We first need to import the Odoo exceptions at the top of the file, shown as follows:
from odoo import exceptions
Then, we add another method with a test case to the test class, shown as follows:
def test_button_send_empty_body(self): "Send button errors on empty body message" wizard0 = self.Wizard.create({}) with self.assertRaises(exceptions.UserError) ...Read now
Unlock full access