In Odoo, Python test cases are added in the tests/ directory of the module. Odoo will automatically identify this directory and run the test under the folder.
Odoo uses Python unittest https://docs.python.org/3.5/library/unittest.html for Python test cases. It also provides some helper classes, wrapped over unittest. These classes simplify the process of developing test cases. In our case, we have used TransactionCase. The TransactionCase runs each test case method in a different transaction. Once a test case method runs successfully, a transaction is automatically rolled back.
The class method starts from test_ and is considered a test case. In our example, we have added two test cases. This checks the methods that change the book's state. The self.assertEqual method is used to check whether the test case runs successfully. We have checked the book state after performing operations on the book's record. So, if the developer made a mistake and the method is not changing states as expected, the test case will be failed.
The docstrings on the methods will be printed in the logger. This will be very helpful for checking the status of the particular test case.