Odoo 12 Development Essentials
上QQ阅读APP看书,第一时间看更新

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_book.py, add a few more lines of code after the test_create() method:

    def test_check_isbn(self): 
"Check valid ISBN"
self.assertTrue(self.book_ode._check_isbn)

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, creating a new book. 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 call the tested method on the created record and check whether the ISBN used is correctly validated.

If we now run the tests, they should fail, since the tested feature has not been implemented yet.