Quick Answer
Test Odoo modules with 5 levels: Unit Tests (TransactionCase for logic), Tours (JS for UI), CI/CD (Odoo.sh auto-testing), UAT (human sign-off), and Sanity Checks (post-deployment monitoring). A bug in production costs 10x more than one caught in development.
Introduction: The "Works on My Machine" Syndrome
Every Odoo developer has said it. "It works on my local server." But when the module hits production, the server crashes, accounting entries don't post, or the warehouse scanner goes blank.
⚠️ The Cost: A bug found in production costs 10x more to fix than one found in development.
In the Odoo ecosystem, testing is often skipped because deadlines are tight. But skipping validation is false economy. This guide provides a robust Testing Framework for Odoo developers and QA leads, covering everything from automated unit tests to final user validation.
Level 1: Automated Unit Testing (The Developer's Responsibility)
Catch logic errors before they leave your laptop.
Odoo has a built-in testing framework based on Python's unittest. You don't need external tools; you just need discipline.
1. The TransactionCase Strategy
This is the bread and butter of Odoo testing. It runs a test in a transaction and rolls it back at the end, keeping your database clean.
Example: Testing a "Commission" Calculation
Create test file: tests/test_commission.py
from odoo.tests.common import TransactionCase
class TestCommission(TransactionCase):
def setUp(self):
super(TestCommission, self).setUp()
self.sale_order = self.env['sale.order'].create({
'partner_id': self.env.ref('base.res_partner_1').id
})
def test_commission_calculation(self):
# Action: Add a line for $100
self.sale_order.order_line = [(0, 0, {
'product_id': self.product.id,
'price_unit': 100.0
})]
# Assertion: Commission should be 10% ($10)
self.assertEqual(
self.sale_order.commission_amount,
10.0,
"Commission calculation failed"
)
2. Running Tests Locally
Don't wait for the server. Run this command:
./odoo-bin -c odoo.conf -d test_db -i my_module --test-enable --stop-after-init
✅ Best Practice: Aim for 80% Code Coverage. Use coverage.py to see which lines of your code aren't being tested.
Level 2: Integration Testing (Tours & UI)
Does the button actually work?
Unit tests check code; Integration tests check workflows. Odoo uses "Tours" (JavaScript tests) to simulate a real user clicking through the interface.
How to Write a Tour:
| Step | Action |
|---|---|
| 1 | Create a JS file in static/src/js/tours/ |
| 2 | Trigger: Click "Create Invoice" |
| 3 | Trigger: Write "100" in amount field |
| 4 | Trigger: Click "Confirm" |
| 5 | Check: Look for the "Posted" status badge |
💡 Why Tours? They catch "White Screen" errors that Python tests miss. If a JavaScript asset is broken, the Tour will fail immediately.
Level 3: The CI/CD Pipeline (The Gatekeeper)
Automate the quality gate.
You should never manually deploy code. Use a Continuous Integration (CI) pipeline (GitHub Actions or Odoo.sh) to block bad code.
The Odoo.sh Workflow:
| Step | What Happens |
|---|---|
| Push Code | Developer pushes to staging branch |
| Auto-Build | Odoo.sh automatically spins up a fresh database |
| Run Tests | It installs your module and runs all tests (Unit + Tours) |
| Result | ✓ Green = Safe to merge | ✗ Red = Merge blocked |
🛡️ Odoo.sh Tip: Use the "Staging" branches for this. Never push directly to Production.
Level 4: User Acceptance Testing (UAT)
The final human check.
Automated tests can't check "usability." Only a human can tell you if a flow is annoying or confusing.
The UAT Protocol:
| Phase | Action |
|---|---|
| Freeze Staging | Deploy the candidate build to a Staging server with a fresh copy of production data |
| The Script | Give key users a script, not just "go play" |
| Example | "Create a Sales Order for Customer X, add a 10% discount, and email it." |
| Sign-Off | Department Head must physically sign off (email/Jira ticket) |
📝 Sign-Off Template: "I have tested the Discount feature and it works as expected. Approved for production deployment." - [Department Head Name]
Level 5: Post-Deployment Validation (Sanity Check)
Did we break anything else?
After deploying to Production, run a "Sanity Check" immediately.
✓ Critical Paths: Check the 3 things that must work (e.g., Website Checkout, POS Login, Invoice Validation).
✓ Monitor Logs: Watch the Odoo logs for the first hour. Look for "Traceback" or "Error."
tail -f /var/log/odoo/odoo-server.log | grep -E "(Traceback|Error)"
Testing Levels Summary
| Level | Type | Checks | Owner |
|---|---|---|---|
| 1 | Unit Tests | Logic, calculations | Developer |
| 2 | Tours (JS) | UI workflows | Developer |
| 3 | CI/CD | Automated gate | Pipeline |
| 4 | UAT | Usability, workflows | Business Users |
| 5 | Sanity Check | Critical paths, logs | DevOps |
Frequently Asked Questions
What is the difference between Unit Tests and Tours?
Unit Tests (Python) check business logic (calculations, constraints) and run fast. Tours (JS) check the user interface (clicks, views) and run slow. You need both for comprehensive coverage.
How do I test email sending in Odoo without spamming real customers?
In your Staging/Test environment, set the Outgoing Mail Server to "Test Mode" or use a tool like Mailtrap. Alternatively, Odoo.sh automatically captures emails in a "Mailcatcher" tab so they never leave the system.
Can I automate testing for existing Odoo modules?
Yes. You can write test cases that inherit from standard modules. For example, you can write a test that ensures the standard "Confirm Sale" button also triggers your custom "Notify Manager" action.
What code coverage percentage should I aim for?
Aim for 80% code coverage as a minimum. Use coverage.py to identify untested code paths. Focus on testing critical business logic first—calculations, constraints, and workflows.
How long should UAT testing take?
Plan for 1-2 weeks of UAT for major releases. For hotfixes, a 1-2 day focused UAT on the affected area is sufficient. Never skip UAT entirely—user sign-off is your safety net.
Conclusion: Quality is a Process
Testing isn't an "extra step"; it is part of development. By implementing a pipeline that includes Unit Tests, Tours, and human UAT, you turn deployment day from a stressful event into a non-event.
Need Help Setting Up a CI/CD Pipeline?
Braincuber can configure your GitHub/Odoo.sh workflow to automate testing completely. Deploy with confidence.
Schedule a DevOps Consultation
Get your CI/CD pipeline configured, testing automated, and deployments stress-free. We'll set up the quality gates that catch bugs before they hit production.
Automated testing • CI/CD setup • Deploy with confidence
