Skip to main content

Testing

Each of the six modules ships its automated tests in its tests folder. Run them after you install or update the modules, after an Odoo update, and with your own modules installed, to see that the modules work with your Odoo and your other modules. This page shows how to run them with Odoo's own odoo-bin, what each suite covers, and how to add tests of your own.

Run a suite​

Run the tests on a new database that exists only for the test run, never on a database with your business data: installing a module with tests enabled runs every test against that database. Tests run with Odoo's demo data, which odoo-bin loads in a new database by default in 18.0; don't pass --without-demo.

odoo-bin --addons-path=<odoo>/addons,<enterprise>,<rx-modules> -d <test-db> \
-i aglow_rx_tracking --test-enable --test-tags /aglow_rx_tracking --stop-after-init
  • <odoo>/addons, <enterprise> and <rx-modules> are the folders of your server's --addons-path (the Enterprise folder only for the Barcode and Suspect Product add-ons and their bridges); <test-db> is the name of the new database.
  • -i <module> installs the module and what it depends on; --test-tags /<module> runs that module's tests only (Odoo's own tests are skipped); --stop-after-init stops the server when the tests are done.
  • Use a new <test-db> for each run, or drop it before the next one.

odoo-bin exits with a non-zero status when a test fails. Still read the end of the log: an error logged outside a test, for example while a module installs, doesn't change the exit status. Check:

  • The result line: odoo.tests.result: 0 failed, 0 error(s) of 676 tests when loading database '<test-db>'.
  • No line logged at ERROR or CRITICAL level: a failed test and an installation error are logged there.

The suites​

Suite-i--test-tagsTests (18.0 release)Needs
Coreaglow_rx_tracking/aglow_rx_tracking676Community
3PL add-onaglow_rx_tracking_3pl/aglow_rx_tracking_3pl783Community
Core with the 3PL add-on installedaglow_rx_tracking_3pl/aglow_rx_tracking,/aglow_rx_tracking_3pl1459Community
Barcode add-onaglow_rx_tracking_barcode/aglow_rx_tracking_barcode16Enterprise, a browser
Suspect Product add-onaglow_rx_tracking_quality/aglow_rx_tracking_quality18Enterprise
Suspect Product add-on with its 3PL bridgeaglow_rx_tracking_3pl_quality/aglow_rx_tracking_quality,/aglow_rx_tracking_3pl_quality32Enterprise
Barcode add-on with its 3PL bridgeaglow_rx_tracking_3pl_barcode/aglow_rx_tracking_barcode,/aglow_rx_tracking_3pl_barcode28Enterprise, a browser

The counts are those of the released 18.0 modules; a later version may add tests, and its changelog says so. Fewer tests than the count means some tests didn't run: read the log.

What they cover:

  • Core: the GS1 library; supplier EPCIS import and the reader (including files that are refused); the EPCIS writer against the EPCIS 1.2 schemas; the trading-partner and serial checks on every path, including imports, Point of Sale and other apps; the package ledger's operations and its write guard; returns, quarantine, scraps, counts and the opening balance; the frozen documents, the hash chain and Verify Integrity; the portal; retention exports, legal holds and the off-site archive (with the S3 calls simulated); trace requests; access rights and record rules; the extension points.
  • 3PL add-on: the switch and its "inert while off" promise; owner stock kept apart in reservation, scans, validation, returns, scraps and counts; owner receipts, owner orders and deliveries; documents in the owner's name; holds and notices; title transfers; the owner portal and exports; and the core's own tests again with the switch on, to show that stock the company owns behaves as in the core.
  • Barcode add-on and bridge: the DataMatrix parsing (JavaScript unit tests) and tours in the Barcode app, plus the owner-aware lot pre-fill of the bridge.
  • Suspect Product add-on and bridge: investigations, Form FDA 3911 and the investigations opened on quarantine, per owner with the bridge.

Browser tests​

The Barcode suites include tours, which drive the Barcode app in a headless Chrome or Chromium. They need a Chrome or Chromium on the server and the websocket-client package in Odoo's Python environment. The environment variable ODOO_BROWSER_BIN can point Odoo at a browser that isn't on the PATH. When either is missing, Odoo skips the tours instead of failing them, and the suite reports fewer tests: 16 and 28 are the counts with the tours included.

The contract tests of the extension points​

Each extension point has contract tests that prove its default and that an override takes effect. After an update of the modules, run them with your module installed to see that the points you use still behave as documented. Odoo's test tags select a test class (/<module>:<Class>) or one test (/<module>:<Class>.<test>):

odoo-bin --addons-path=<odoo>/addons,<rx-modules>,<your-modules> -d <test-db> -i aglow_rx_tracking_3pl,<your-module> \
--test-enable --stop-after-init --test-tags \
/aglow_rx_tracking:TestExtensionSeams,/aglow_rx_tracking:TestExtensionSeamsEpcis,/aglow_rx_tracking:TestExtensionSeamReturns,/aglow_rx_tracking_3pl:TestThreePLHooks,/<your-module>

A contract test may fail with your module installed when your override changes the very behaviour it checks: that is expected for the point you override, and your own tests take over there. The rest of the modules' suites should still pass.

Your own tests​

  • One test file per feature in your module's tests folder, imported in tests/__init__.py.
  • odoo.tests.TransactionCase (each test runs in a transaction that is rolled back), tagged @tagged("post_install", "-at_install") so it runs once every module is installed.
  • For every check you add, one test that it refuses what it should and one that a line of a product that isn't a DSCSA product passes unchanged.
  • The modules' test classes have helpers you can build on (receipts, scans, validations, owner stock); the examples on Extending the modules use them. They are not an extension point: a new version may change them, so run your tests after every update.