---
question: How do I test a module, offline and running?
kind: guide
---

# Test a module

A module is tested in two steps: offline, with no broker and no engine, then running next to the stack.

## Offline

`abi new module` writes `tests/module_test.py` in the module's package. It runs with no broker:

```bash
uv run --with pytest pytest src/research/tests
```

The scaffolded tests check that:

- the module declares its agent, the services it calls, its job and its workflow;
- every class under `workflows/` and `pipelines/` imports and is named after its class (a broken import, or two classes with one name, fails here);
- the module sends its ontologies to the engine;
- the module never imports `naas_abi_core`, in a separate interpreter;
- the module signs its calls as its own module id, and `SIGTERM` stops it cleanly.

Keep them, and add your own beside them. Units need no engine either: a workflow's `run(...)`, a pipeline's graph, an integration with its HTTP client mocked. `abi new workflow`, `abi new pipeline` and `abi new integration` write a test beside each class:

```python title="workflows/CustomersWorkflow_test.py"
import asyncio

from .CustomersWorkflow import (
    CustomersWorkflow,
    CustomersWorkflowConfiguration,
    CustomersWorkflowParameters,
)


def test_the_workflow_runs() -> None:
    workflow = CustomersWorkflow(CustomersWorkflowConfiguration())
    result = asyncio.run(workflow.run(CustomersWorkflowParameters(message="hi")))
    assert result == {"message": "hi"}
```

Keep job bodies in `jobs.py`, apart from the class, so they test without a broker too.

## Running

Start the stack and the module, then read its log:

```bash
abi dev up
abi dev logs research -f    # "... READY: registered in discovery"
```

A module that never logs `READY` says why every 15 seconds: discovery is not running, or `ABI_MODULE_KEY` is not this module's. Once it is `READY`, the Nexus System app shows it on the **Modules** tab and its jobs on the **Jobs** tab, where **Run now** triggers one. Restart only the module after a change:

```bash
abi dev down --service research
abi dev up -d --service research
```

The Docker build is a test too: the module's `Dockerfile` fails when `naas_abi_core` is installed, or when the module cannot be imported without it.

The scaffold and the run commands are on [Creating a Module](/capabilities/build/modules/creating-a-module#run-it-with-abi-dev-up).
