Skip to Content

Testing Framework for Odoo

What kind of software testing tools and methods can be used for Odoo developments

In today's fast-paced business world, your software needs to be reliable and rock-solid to help you succeed. Odoo, a powerful open-source business management system, brings a ton of features and tools to make your operations smoother. But to really get the most out of your Odoo setup and ensure it's stable, you absolutely can't skip software testing. In this post, we're going to dive into the basics of testing in Odoo and even show you some code examples to help you build a winning testing plan.

When we talk about software testing in Odoo, we're essentially checking that the system's features, speed, and ease of use are all up to snuff. It's how we make sure every part of Odoo, from its standard modules to any custom tweaks you've added, is doing exactly what it's supposed to and truly meets your business needs. Good testing helps us catch and fix any problems before the system goes live. This cuts down on potential headaches and makes sure users are happy with the final product.

🔹 1. Odoo’s Built-in Testing Framework (Unittest-based)

Odoo includes a built-in testing framework based on Python’s unittest module. It is the recommended and most widely used framework for testing Odoo modules.

✅ Key Features:

  • Integrates directly with Odoo’s ORM and environment.
  • Supports model tests, business logic tests, workflows, access rights, and more.
  • Can be run using Odoo CLI (--test-enable, --test-tags).

✅ How to Write:

python

CopyEdit

from odoo.tests.common import TransactionCase class TestSaleOrder(TransactionCase): def test_create_order(self): order = self.env['sale.order'].create({ 'partner_id': self.env.ref('base.res_partner_1').id, }) self.assertTrue(order)

✅ Types of Built-in Test Cases:

  • TransactionCase: Rolls back each test, used for most logic-based tests.
  • HttpCase: For website, controllers, or frontend interaction tests.
  • SavepointCase: Faster, used when rollback is not needed between tests.

🔹 2. Postman or Swagger (for API Testing)

  • Useful when you develop REST APIs or JSON-RPC endpoints in your module.
  • Write and automate test collections using Postman.
  • Document and test OpenAPI endpoints using Swagger UI if integrated.

🔹 3. Pytest (Optional, External)

  • While not officially part of Odoo, pytest can be adapted to test Odoo modules.
  • Good for developers who prefer pytest syntax and features like fixtures, parametrization.
  • Requires some configuration to work within Odoo's environment.

🔹 4. Selenium (for UI/Frontend Testing)

  • Use Selenium for end-to-end browser testing of Odoo’s web interface.
  • Odoo’s HttpCase also supports JavaScript testing using phantomJS (deprecated), or real browsers via Selenium/Webdriver.

Example:

python

CopyEdit

class TestWebInterface(HttpCase): def test_01_login_page(self): self.browser_js("/web/login", "console.log('Login Page Loaded')", ready="odoo.__DEBUG__.services['web.session']")

🔹 5. OCA Quality Tools (CI/CD Testing)

  • Odoo Community Association (OCA) provides a pre-commit framework that includes:
    • Pylint Odoo (code style)
    • Dependency checks
    • Migration checks
  • Can be integrated into GitHub/GitLab pipelines for automated testing.

Repo: https://github.com/OCA/oca-addons-repo-template

🧪 How to Run Odoo Tests

Via CLI:

bash

CopyEdit

odoo --test-enable -i your_module_name -d test_db

To filter tests using tags:

bash

CopyEdit

odoo --test-enable --test-tags=/your_module_name -i your_module_name -d test_db

🧩 Summary Table

Framework/ToolPurposeNotes
unittest (Odoo)Unit, transaction, integrationBuilt-in and recommended
HttpCaseController and web testsSupports Selenium/JS
pytestCustom unit testing frameworkExternal, optional
PostmanAPI endpoint testingGood for REST/JSON-RPC
SeleniumUI/browser testingFor full end-to-end tests
OCA Pre-commitCode quality & CI testsGood for Git integration

/se

✅ 1. Sample Unit Test File for an Odoo Module

Let’s assume your custom module is called my_custom_module.

📁 File structure:

markdown

CopyEdit

my_custom_module/ ├── __init__.py ├── __manifest__.py ├── models/ │ └── my_model.py ├── tests/ │ └── test_my_model.py

📄 test_my_model.py

python

CopyEdit

from odoo.tests.common import TransactionCase class TestMyModel(TransactionCase): def setUp(self): super().setUp() self.partner = self.env['res.partner'].create({ 'name': 'Test Partner', 'email': 'test@example.com' }) def test_create_record(self): my_record = self.env['my_custom_model'].create({ 'name': 'Test Record', 'partner_id': self.partner.id }) self.assertTrue(my_record.id) self.assertEqual(my_record.partner_id.name, 'Test Partner')

⚙️ 2. GitHub Actions CI Workflow for Odoo

This example uses OCA's prebuilt Docker image and supports:

  • Dependency installation
  • Linting
  • Unit tests

📁 .github/workflows/ci.yml

yaml

CopyEdit

name: Odoo CI on: push: branches: [main] pull_request: jobs: odoo-test: runs-on: ubuntu-latest services: postgres: image: postgres:13 env: POSTGRES_USER: odoo POSTGRES_PASSWORD: odoo POSTGRES_DB: odoo ports: ['5432:5432'] options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 steps: - name: Checkout code uses: actions/checkout@v3 - name: Set up Python uses: actions/setup-python@v4 with: python-version: 3.10 - name: Install dependencies run: | sudo apt-get update sudo apt-get install -y python3-pip libxml2-dev libxslt1-dev libldap2-dev libsasl2-dev libpq-dev pip install wheel pip install -r requirements.txt - name: Run Odoo Tests run: | git clone https://github.com/odoo/odoo.git --depth=1 --branch=17.0 ./odoo/odoo-bin --addons-path=./odoo/addons,./my_custom_module -d test_db --test-enable --stop-after-init -i my_custom_module --db-user=odoo

🧪 What This Does:

🧩 Optional Enhancements:

  • Integrate pylint-odoo for style checking:

    bash

    CopyEdit

    pip install pylint-odoo pylint --load-plugins=pylint_odoo my_custom_module

  • Add coverage report using coverage.py
  • Run tests across multiple Odoo versions using a test matrix


Odoo's Test Framework: Best Practices


Also read: 

A Complete Guide to Software Testing in Odoo, with Code Examples

How to write Test Case in the Odoo 17 ERP



CONTACT US

​​iF YOU WANT TO HIRE OODOO DEVELOPERS AT COMPETITIVE RATE, CONTACT US AT WHATSAPP 8801924572887


Share this post
Tags
Archive
Software Component Diagram of Odoo 18 Enterprise Edition