Introduction to writing and using (automated) tests
Welcome to the testing tutorial for Odoo.
What are we going to be dealing with? In this tutorial, we are not going to get into more advanced concepts and ideas around how or what. Those are all things that are debated throughout development communities and that end up being very personal to the types of team or application.
I want to walk through a realistic use-case of a sample module and then show you the process for writing and running some basic tests.
One question you may immediately be thinking is, why should I write tests?
Usually programmers test the code that they've written. It’s something that we most of us are very accustomed to. But many Odoo developers are not taking full advantage of the automated testing tools provided to us by the framework and by the python language.
Writing tests has benefits for most teams, with each team benefiting in different ways. For me, the most important factor is actually not quantifiable. It makes me a less stressed and happier programmer because I know that I’m slowly sowing my own safety net for a project. As each major feature or use case gets a test confirming how it’s expected to work, then that protects me from accidentally deploying broken code. We can’t pull up a large application and manually test all aspects every deployment. Also, as each bug arises a test can be added to confirm that the bug has been resolved and again prevents us from regressing and deploying broken code. In this case, the work kind of broken code being a bug that the client has asked you to fix already.
There are many, many types of tests floating around out there. Then there are also multiple names per type of tests depending on who you are talking to. Integration, unit, functional, etc. You can dig into all of these down the road as you get further into testing. Just start writing tests that replicate the same steps you would take manually.
So I’m going to try to give you all of the tools that you need to get started with testing. In my experience, testing is not as prolific within the Odoo community compared to others, so I’m hoping that this gives a kick start to Odoo developers out there!