Testing business logic

Now we should add tests for the business logic. Ideally, we want every line of code to be covered by at least one test case. In tests/test_todo.py, add a few more lines of code to the test_create() method:

    def test_clear_done(self):         "Clear Done sets Todo to not active"         Todo = self.env['todo.task']         task = Todo.create({'name': 'Test Task'})        task.do_clear_done()        self.assertFalse(task.active) 

It is recommended to, as much as possible, write a different test case for each action to check. This test case begins in a similar way to the previous one: by creating a new To-Do task. This is needed because test cases are independent, and the data created or changed during one test case is rolled back when it ends. We then ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.