Claude
Skills
Sign in
Back

odoo-test

Included with Lifetime
$97 forever

Comprehensive Odoo testing toolkit for generating test skeletons, running test suites, creating mock data, and analyzing test coverage across Odoo 14-19. Supports TransactionCase, HttpCase, SavepointCase, and integrates with Azure DevOps for CI/CD test result reporting. <example> Context: User wants test cases for a custom model user: "Generate test cases for my custom sale.order extension module" assistant: "I will use the odoo-test skill to analyze the model definition and generate TransactionCase test skeletons covering CRUD operations, computed fields, and business logic." <commentary>Core trigger - test skeleton generation from model definition.</commentary> </example> <example> Context: User wants mock data for testing user: "Create realistic mock data for testing my inventory module" assistant: "I will use the odoo-test skill to generate a mock data factory with realistic product, partner, and stock.move records using Odoo demo data patterns." <commentary>Test data creation trigger.</commentary> </example> <example> Context: User wants to analyze test coverage user: "Show me which parts of my module have no test coverage" assistant: "I will use the odoo-test skill to scan the module for untested models, methods, and views, then generate a coverage report with priority recommendations." <commentary>Coverage analysis trigger - finding gaps in the test suite.</commentary> </example> <example> Context: User wants test skeletons for a model user: "Generate test cases for my sale.order extension" assistant: "I will analyze the model definition and generate TransactionCase test skeletons covering CRUD, computed fields, and business logic." <commentary>Test generation trigger.</commentary> </example> <example> Context: User wants mock data user: "Create realistic mock data for testing my inventory module" assistant: "I will generate a mock data factory with realistic product, partner, and stock.move records using Odoo demo data patterns." <commentary>Mock data trigger.</commentary> </example> <example> Context: User wants to run tests user: "Run tests for my custom module with post_install tag" assistant: "I will execute the test suite with --test-enable and --test-tags=post_install, showing colored output." <commentary>Test run trigger.</commentary> </example> <example> Context: User wants coverage analysis user: "Show me which parts of my module have no test coverage" assistant: "I will scan for untested models, methods, and views, then generate a coverage report with priority recommendations." <commentary>Coverage analysis trigger.</commentary> </example> <example> Context: User wants E2E tests user: "Generate Playwright E2E tests for my Odoo module" assistant: "I will create Playwright test files covering login, navigation, form submission, and data validation for the module's web interface." <commentary>E2E test trigger.</commentary> </example>

Cloud & DevOpsscripts

What this skill does


# Odoo Testing Toolkit Skill (v2.0)

> **v2.0 Architecture**: All testing operations available via `/odoo-test` sub-commands or natural language.

A comprehensive skill for generating, running, and analyzing tests across Odoo 14-19. Covers unit tests, integration tests, HTTP controller tests, mock data creation, and test coverage analysis. Includes CI/CD integration patterns for Azure DevOps pipelines.

## Configuration

- **Supported Versions**: Odoo 14, 15, 16, 17, 18, 19
- **Primary Version**: Odoo 17
- **Test Patterns**: 80+ documented patterns
- **Mock Data Generators**: 20+ field-type-aware generators
- **Core Base Class**: `odoo.tests.common.TransactionCase`
- **Test Runner**: Built-in Odoo test framework + CLI scripts

---

## Quick Reference

### All Commands

| Command | Purpose | Example |
|---------|---------|---------|
| `/odoo-test` | Full testing workflow | `/odoo-test my_module` |
| `/test-generate` | Generate test skeleton | `/test-generate --model my.model --module /path/to/module` |
| `/test-run` | Run test suite | `/test-run my_module --tags post_install` |
| `/test-coverage` | Analyze coverage | `/test-coverage /path/to/module` |
| `/test-data` | Generate mock data | `/test-data --model res.partner --count 10` |

### One-Liner Command Reference

```bash
# Generate test skeleton for a model
python test_generator.py --model sale.order --module /c/odoo/odoo17/projects/myproject/my_module

# Run tests for a module
python -m odoo -c conf/project17.conf -d project17 --test-enable -i my_module --stop-after-init

# Run tests with specific tags
python -m odoo -c conf/project17.conf -d project17 --test-enable --test-tags=post_install --stop-after-init

# Run specific test class
python -m odoo -c conf/project17.conf -d project17 --test-enable --test-tags=/my_module:TestMyModel --stop-after-init

# Analyze coverage
python coverage_reporter.py --module /path/to/my_module

# Generate 10 mock partner records
python mock_data_factory.py --model res.partner --count 10
```

---

## Testing Architecture

### Test Class Hierarchy

```
┌─────────────────────────────────────────────────────────────────────────────┐
│                    ODOO TEST CLASS HIERARCHY                                   │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                               │
│  unittest.TestCase (Python standard)                                          │
│  └── odoo.tests.common.BaseCase                                              │
│       ├── TransactionCase          ← MOST COMMON                             │
│       │   • Each test wrapped in transaction rolled back on completion        │
│       │   • Full ORM access via self.env                                      │
│       │   • Database state reset between tests                                │
│       │   • setUpClass() for shared expensive setup                           │
│       │                                                                       │
│       ├── SavepointCase (Odoo 14-15) / TransactionCase with savepoints        │
│       │   • Allows partial rollback within a test                             │
│       │   • Useful for testing exception handling                             │
│       │   • Use self.cr.savepoint() context manager                           │
│       │                                                                       │
│       └── HttpCase                 ← FOR WEBSITE/API                         │
│           • Starts real HTTP server on localhost                              │
│           • Supports phantom_js() / browser_js()                              │
│           • Supports jsonrpc() / url_open()                                   │
│           • Full route testing with authentication                            │
│                                                                               │
└─────────────────────────────────────────────────────────────────────────────┘
```

### TransactionCase vs HttpCase vs SavepointCase

| Feature | TransactionCase | SavepointCase | HttpCase |
|---------|----------------|---------------|----------|
| DB Isolation | Per test (rollback) | Per class (savepoints) | Per test (rollback) |
| HTTP server | No | No | Yes (localhost) |
| Speed | Fast | Medium | Slow |
| Best for | ORM/business logic | Exception testing | Routes, UI, JSON |
| Auth control | Direct `self.env` | Direct `self.env` | `self.authenticate()` |
| Access | `env.user` | `env.user` | Via HTTP session |

### When to Use Each

```python
# TransactionCase - Business logic, CRUD, compute, constraints, workflows
class TestSaleOrder(TransactionCase):
    def test_order_confirmation(self):
        order = self.env['sale.order'].create({...})
        order.action_confirm()
        self.assertEqual(order.state, 'sale')

# HttpCase - Website routes, API endpoints, authenticated pages
class TestWebsiteController(HttpCase):
    def test_shop_page(self):
        self.authenticate('admin', 'admin')
        res = self.url_open('/shop')
        self.assertEqual(res.status_code, 200)

# SavepointCase - When you need to test that an exception rolls back properly
class TestConstraints(TransactionCase):
    def test_constraint_rollback(self):
        with self.assertRaises(ValidationError):
            self.env['my.model'].create({'required_field': False})
```

---

## Test Tagging System

### Tag Decorator Reference

```python
from odoo.tests import tagged

# Most common - runs after all modules installed (stable environment)
@tagged('post_install', '-at_install')
class TestMyModel(TransactionCase):
    pass

# Runs during module install (early execution, limited env)
@tagged('at_install', '-post_install')
class TestEarlyLogic(TransactionCase):
    pass

# Standard tests (default, equivalent to post_install)
@tagged('standard')
class TestStandard(TransactionCase):
    pass

# Explicitly exclude from automatic runs
@tagged('-standard', 'manual')
class TestManualOnly(TransactionCase):
    pass

# Multiple tags
@tagged('post_install', '-at_install', 'sale', 'critical')
class TestSaleIntegration(TransactionCase):
    pass
```

### Tag Precedence Rules

```
Tag with '-' prefix = EXCLUSION (remove from selection)
Tag without '-'    = INCLUSION (add to selection)

Default run: --test-tags=standard
Post-install: --test-tags=post_install (most common for production tests)

Examples:
  --test-tags=post_install           → all post_install tagged tests
  --test-tags=my_module              → all tests in module my_module
  --test-tags=/my_module:MyClass     → specific class in module
  --test-tags=/my_module:MyClass.test_method  → specific method
```

### Built-in Odoo Tags

| Tag | When it runs | Use case |
|-----|-------------|----------|
| `standard` | Default CI runs | Unit tests, business logic |
| `at_install` | During install | Basic module integrity |
| `post_install` | After all installs | Integration, full env tests |
| `slow` | Skipped by default | Long-running tests |
| `external` | Skipped by default | External API tests |
| `multi_company` | Special flag | Multi-company scenarios |

---

## Writing Tests

### Complete CRUD Test Pattern

```python
from odoo.tests import TransactionCase, tagged
from odoo.exceptions import ValidationError, UserError

@tagged('post_install', '-at_install')
class TestMyModel(TransactionCase):
    """Test suite for my.model CRUD operations and business logic."""

    @classmethod
    def setUpClass(cls):
        """Set up class-level fixtures shared across all tests in this class.
        Called once before any test method in the class.
        """
        super().setUpClass()
        # Create shared records (not rolled back between tests)
        cls.partner = cls.env['res.partner'].create({
            'name': 'Test Partner',
            'email': '[email protected]',
        })
        cls.currency = cls.env.ref('base.USD')
        cls.company = cls.

Related in Cloud & DevOps