← ClaudeAtlas

testing-with-lexigramlisted

Use when writing tests, creating test environments, or using stubs/fakes in the Lexigram framework
dbtinoy-/lexigram-framework-skills · ★ 1 · Testing & QA · score 72
Install: claude install-skill dbtinoy-/lexigram-framework-skills
# Testing with Lexigram ## Overview Lexigram's DI container makes testing straightforward: fake at the contract boundary, use `TestEnvironment` for isolation, and use `stub()` modules for full integration tests. ## TestEnvironment ```python from lexigram.testing import TestEnvironment from lexigram.testing.fakes import FakeCache from lexigram.contracts.infra.cache import CacheBackendProtocol async def test_user_service(): # extra_registrations is a callable receiving the container env = TestEnvironment( extra_registrations=lambda c: c.singleton( CacheBackendProtocol, instance=FakeCache() ) ) await env.setup() service = await env.container.resolve(UserService) result = await service.get_user("user-123") assert result.is_ok() await env.teardown() ``` Each `TestEnvironment` is fully isolated — no global state pollution. ## Module Stubs ```python @module(imports=[ LLMModule.stub(), # No-op LLM EventsModule.stub(), # In-memory events DatabaseModule.stub(), # In-memory DB ]) class TestModule(Module): pass async def test_with_modules(): async with Application.boot(modules=[TestModule]) as app: service = await app.container.resolve(MyService) result = await service.process() assert result.is_ok() ``` Every extension package should define `stub()` returning a `DynamicModule` with in-memory/noop backends. ## Testing Result-Returning Methods ```python @pytest.mark.as