Skip to content

Testing 🟑 BETA

Tests are split by the boundary they cross and run one crate at a time in the development container.

Where this topic sits in the Developer guide

Overview

Tests are split by boundary: unit tests beside the code, integration tests under bottest/tests/integration/, end-to-end suites under bottest/tests/e2e/.

Test Organization

Directory Contents
crate src/ Inline #[cfg(test)] modules
bottest/tests/unit/ Workspace unit policy checks
bottest/tests/integration/ Cross-crate workflows, tenant isolation
bottest/tests/e2e/ Browser flows through CDP

Directory Structure

bottest supplies harness, services, mocks, fixtures and a CLI driver; it is a binary and test crate with features integration, e2e and full.

Test Files

A test file name states the behaviour it covers; suites are registered as Cargo test targets in bottest/Cargo.toml.

Running Tests

  1. cargo test -p <crate> --lib for a crate.
  2. cargo test -p botserver --bin botserver for the server binary.
  3. cargo test -p bottest --features integration tenant_isolation before touching tenant-scoped handlers.
  4. cargo test -p bottest --features e2e for browser suites.

All Tests

One crate at a time: the full workspace graph does not fit the 4.5 GiB development container.

Test Coverage

The per-crate function inventory is on the Unit test coverage by crate page; line and branch coverage come from the CI coverage job.

Unit Testing

A unit test asserts one behaviour of one module and needs no external service.

Basic Test Structure

Arrange, act, assert; keep the setup in a fixture when it is reused.

Async Tests

Use #[tokio::test] where the code is async; keep the runtime single-threaded for determinism.

Integration Testing

Integration tests start the services the workflow needs and assert across crate boundaries.

Database Tests

Use a throwaway database; never point a test at the developer or production database.

API Tests

Register the route in source before testing it; a route that does not exist is not a test target.

BASIC Script Testing

Script tests compile a .bas source through botbasic_compiler and assert the registered keyword behaviour.

Testing Keywords

Search the keyword registry first; an unregistered keyword cannot be tested as a feature.

Testing Script Compilation

Compiler tests live in botbasic_compiler; script runtime tests live under bottest/tests/integration/basic_runtime/.

Test Utilities

Fixtures, mocks and port allocation live in bottest/src/; reuse them instead of starting ad-hoc services.

Test Fixtures

Fixtures recreate data for each case so tests stay independent of order.

Mock Objects

LLM, Zitadel, Teams and WhatsApp mocks avoid live providers and paid calls.

Performance Testing

Measure a single crate or service; do not run a full workspace benchmark in the dev container.

Benchmarks

No benchmark suite is documented here; performance gates are CI jobs.

Load Testing

Load tests are operator evidence, not a local default.

Test Best Practices

  • Deterministic mocks over live providers.
  • One assertion theme per test.
  • No test depends on another test's state.
  • No boteval locally.

Test Naming

Use the test_ prefix and name the behaviour.

Test Independence

Each case recreates its data and releases its ports.

Test Data

Data comes from fixtures, never from production or Drive.

Continuous Integration

.github/workflows/ci.yml runs the gates on pushes and pull requests; the Forgejo runner mirrors them.

Test Documentation

Document the purpose of a non-obvious test in the test module, not in a separate plan.

Document Test Purpose

State which regression the test prevents.

Common Testing Patterns

Arrange-Act-Assert and Given-When-Then are both used; choose one and keep it consistent in a file.

Arrange-Act-Assert

Separate setup, action and assertion.

Given-When-Then

Use for conversation and workflow cases.

Deterministic chat mock

The LLM mock returns a fixed reply so a chat assertion never depends on a model.

Summary

A test is evidence: it must reproduce the behaviour without paid calls, external credentials or ordering assumptions.

Limits

  • cargo test -p botserver alone tests nothing; use --bin botserver.
  • integration and e2e are separate features; full enables both.
  • Boteval runs on CI only.
  • The tenant isolation suite is mandatory before any tenant, bucket or org scoped change.