Version: 6.2.0
Purpose: Test infrastructure for General Bots ecosystem
Bottest provides the comprehensive testing infrastructure for the General Bots ecosystem, including unit tests, integration tests, and end-to-end (E2E) tests. It ensures code quality, reliability, and correct behavior across all components of the platform.
The test harness handles service orchestration, mock servers, fixtures, and browser automation, making it easy to write comprehensive tests that cover the entire system from database operations to full user flows.
For comprehensive documentation, see docs.pragmatismo.com.br or the BotBook for detailed guides and testing best practices.
E2E tests use USE_BOTSERVER_BOOTSTRAP=1 mode. The botserver handles all service installation during bootstrap.
TestHarness::full() / E2E Tests
β
βββ Allocate unique ports (15000+)
βββ Create ./tmp/bottest-{uuid}/
β
βββ Start mock servers only
β βββ MockZitadel (wiremock)
β βββ MockLLM (wiremock)
β
βββ Start botserver with --stack-path
β βββ Botserver auto-installs:
β βββ PostgreSQL (tables)
β βββ MinIO (drive)
β βββ Redis (cache)
β
βββ Return TestContext
#[test]
fn test_pure_logic() {
// No TestHarness needed
assert_eq!(add(2, 3), 5);
}#[tokio::test]
async fn test_with_database() {
let ctx = TestHarness::quick().await?;
let pool = ctx.db_pool().await?;
// Use real database
let user = fixtures::admin_user();
ctx.insert(&user).await;
// Test database operations
}#[tokio::test]
async fn test_user_flow() {
let ctx = TestHarness::full().await?;
let server = ctx.start_botserver().await?;
let browser = Browser::new().await?;
// Automate browser
browser.goto(server.url()).await?;
browser.click("#login-button").await?;
// Verify user flow
assert!(browser.is_visible("#dashboard").await?);
}ctx.mock_llm().expect_completion("hello", "Hi there!");ctx.mock_llm().assert_called_times(2);ctx.mock_llm().next_call_fails(500, "Internal error");ctx.mock_zitadel().expect_login_success("user@example.com", "password");let user = fixtures::admin_user();
let bot = fixtures::bot_with_kb();
let session = fixtures::active_session(&user, &bot);ctx.insert(&user).await;
ctx.insert(&bot).await;
ctx.insert(&session).await;fn custom_bot() -> Bot {
Bot {
name: "Test Bot".to_string(),
enabled: true,
..fixtures::base_bot()
}
}- Each test gets unique ports via PortAllocator
- Each test gets unique temp directory
- No shared state between tests
- Safe to run with
cargo test -j 8
EVERY SINGLE WARNING MUST BE FIXED. NO EXCEPTIONS.
β NEVER use #![allow()] or #[allow()] in source code
β NEVER use _ prefix for unused variables - DELETE or USE them
β NEVER use .unwrap() - use ? or proper error handling
β NEVER use .expect() - use ? or proper error handling
β NEVER use panic!() or unreachable!()
β NEVER use todo!() or unimplemented!()
β NEVER leave unused imports or dead code
β NEVER add comments - code must be self-documenting
// β WRONG
let value = something.unwrap();
// β
CORRECT
let value = something?;
let value = something.ok_or_else(|| Error::NotFound)?;
// Use Self in Impl Blocks
impl TestStruct {
fn new() -> Self { Self { } } // β
Not TestStruct
}
// Derive Eq with PartialEq
#[derive(PartialEq, Eq)] // β
Always both
struct TestStruct { }
// Inline Format Args
format!("Hello {name}") // β
Not format!("{}", name)cargo test -p bottest# Unit tests only
cargo test -p bottest --lib
# Integration tests
cargo test -p bottest --test '*'
# E2E tests only
cargo test -p bottest --test '*' -- --ignoredcargo test -p bottest -- --nocapturecargo test -p bottest -j 8bottest/
βββ src/
β βββ lib.rs # Test harness exports
β βββ harness.rs # TestHarness implementation
β βββ context.rs # TestContext for resource access
β βββ mocks/ # Mock server implementations
β β βββ zitadel.rs
β β βββ llm.rs
β βββ fixtures.rs # Factory functions
β βββ utils.rs # Testing utilities
βββ tests/ # Integration and E2E tests
β βββ integration/
β β βββ database_tests.rs
β β βββ api_tests.rs
β βββ e2e/
β βββ user_flows.rs
βββ Cargo.toml
All testing documentation is located in botbook/src/17-testing/:
- README.md - Testing overview and philosophy
- e2e-testing.md - E2E test guide with examples
- architecture.md - Testing architecture and design
- best-practices.md - Best practices and patterns
- mock-servers.md - Mock server configuration
- fixtures.md - Fixture usage and creation
- docs.pragmatismo.com.br - Full online documentation
- BotBook - Local comprehensive guide
- Testing Best Practices - Detailed testing guidelines
| Project | Description |
|---|---|
| botserver | Main API server (tested) |
| botui | Web UI (E2E tested) |
| botlib | Shared library |
| botbook | Documentation |
- ZERO WARNINGS - Every clippy warning must be fixed
- NO ALLOW ATTRIBUTES - Never silence warnings
- NO DEAD CODE - Delete unused code
- NO UNWRAP/EXPECT - Use ? operator
- INLINE FORMAT ARGS -
format!("{name}")notformat!("{}", name) - USE SELF - In impl blocks, use Self not type name
- Reuse bootstrap - Don't duplicate botserver installation logic
- Parallel safe - Each test gets unique ports and directories
- Version 6.2.0 - Do not change without approval
- GIT WORKFLOW - ALWAYS push to ALL repositories (github, pragmatismo)
AGPL-3.0 - See LICENSE for details.