Back to Top

Odoo testing using ODOO CLI

Updated 8 July 2024

  1. This article offers a comprehensive overview of conducting module testing using the Odoo CLI for developers.
  2. Before starting this tutorial, we assume that you have a foundational understanding of the Command Line Interface (CLI) in Odoo. If you lack this fundamental knowledge, it is advisable to acquaint yourself with a beginner’s guide to Odoo CLI.

What is the significance of utilizing the Command Line Interface (CLI) for conducting Odoo testing?

Performing Odoo testing with the help of the Command Line Interface (CLI) offers several advantages:

  • Automation: CLI automation streamlines various testing tasks, enabling tests to run automatically, which saves time and effort compared to manual testing.
  • Integration with Continuous Integration (CI) Tools: CLI integrates seamlessly with many Continuous Integration (CI) tools like Jenkins, GitLab CI/CD, etc., facilitating the integration of testing processes into larger development pipelines.
  • Headless Operation: You can use CLI in headless mode, meaning it operates without requiring a graphical user interface. This makes it suitable for running tests on servers or in environments without a graphical interface.
  • Reproducibility: CLI testing allows for consistent and reproducible results. Running tests consistently across different environments ensures reliable results.
  • Customization: Developers can customize test runs by specifying various parameters and options through the CLI.

Before moving ahead, check out our Odoo development services & an extensive range of quality Odoo Apps.

How to perform testing using Odoo CLI?

Write Tests:

  • To write tests, create a tests sub-package in your module.The system will automatically inspect it for test modules. Test modules should have a name starting with test_ and should be imported from tests/__init__.py.

Example directory structure:

your_module
├── ...
├── tests
|   ├── __init__.py
|   ├── test_bar.py
|   └── test_foo.py

Contents of __init__.py:

Searching for an experienced
Odoo Company ?
Find out More
from . import test_foo, test_bar

Run Tests After Module Installation :

  1. To run tests automatically after module installation, use the --test-enable flag. Here “.” represents the current directory (where the executable file odoo-bin is present).
  2. “-d” or “-database” specifies the particular database you want to automatically run tests for after module installation.
  3. The --logfile=/ option specifies the file path and name where the Odoo server will write its log output.

Syntax:-

./odoo-bin -d cli_database --test-enable --logfile=/

Output for the above command

Screenshot-from-2023-10-23-11-05-11

Run Specific Test Files :

  • If you have specific test files you want to execute, use the --test-file <file> option
./odoo-bin -d cli_database --test-file addons/account/tests/test_account_account.py

Output for the above command

1-13

Apply Test Tags for Filtering :

  • So if you want to test the stock_account module, you can use:
    “./odoo-bin –test-tags /stock_account”
  • --test-tags: This Odoo command-line option specifies which tests to execute. In this case, the tests you specify after this option are the ones that will be run.
  • :TestAccountMove.test_out_invoice_auto_post_monthly,TestAccountMove.test_included_tax: These are the test tags or labels. They are used to categorize and identify specific tests in Odoo. In this command, it’s telling Odoo to run two specific tests:
    1. TestAccountMove.test_out_invoice_auto_post_monthly: This likely refers to a specific test method named test_out_invoice_auto_post_monthly inside a class named TestAccountMove.
    2. TestAccountMove.test_included_tax: Similarly, this likely refers to a specific test method named test_included_tax inside a class named TestAccountMove.
./odoo-bin -d cli_database --test-tags :TestAccountMove.test_out_invoice_auto_post_monthly,TestAccountMove.test_included_tax

Output for the above command

3-10

Generate Screenshots of Test Failures:

  • When running tests that use HttpCase.browser_js from the command line, the Chrome browser is used in headless mode. The system takes a PNG screenshot at the moment of a test failure by default and writes it in ‘/tmp/odoo_tests/{db_name}/screenshots/’.
  • Two new command line arguments were added since Odoo 13.0 to control this behavior: --screenshots and --screencasts
  • Recording a video for the test case requires the ffmpeg package.

“For further details on Odoo testing procedures, including advanced testing techniques and best practices, please refer to the official Odoo developer documentation on testing: Odoo Testing Documentation

NEED HELP?

Hope you find the guide helpful! Please feel free to share your feedback in the comments below.

If you still have any issues/queries regarding the same, please raise a ticket at the UV Desk.

For any doubt, contact us at our support mail.

. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Back to Top

Message Sent!

If you have more details or questions, you can reply to the received confirmation email.

Back to Home