The Lux test suite is organized into two main categories:
- Unit Tests: Fast, isolated tests that don't require external services
- Integration Tests: Tests that interact with external services (e.g., OpenAI, Alchemy)
# Run unit tests only
mix test.unit
# Run integration tests only (requires API keys)
mix test.integration
# Run python tests
mix python.test
test/unit/
- Contains all unit teststest/integration/
- Contains all integration teststest/support/
- Shared test helpers and utilities
Unit tests use mock configurations and don't require real API keys. The configuration is loaded from:
test.envrc
- Base test configurationtest.override.envrc
- Local overrides (git-ignored)
Integration tests require actual API keys as they interact with external services. To run integration tests:
- Create a
test.override.envrc
file (if not exists) - Add your API keys:
# test.override.envrc
INTEGRATION_OPENAI_API_KEY="your-openai-key"
ALCHEMY_API_KEY="your-alchemy-key"
# Add other required API keys
test.override.envrc
file which is git-ignored.
defmodule MyModuleTest do
use UnitCase, async: true
# Your test code
end
defmodule MyIntegrationTest do
use IntegrationCase, async: true
# Your test code
end
For tests that mock HTTP requests:
defmodule MyAPITest do
use UnitAPICase, async: true
# Your test code
end
-
Test Isolation
- Keep unit tests independent of external services
- Use mocks appropriately in unit tests
- Integration tests should be clearly marked
-
Configuration Management
- Use
test.override.envrc
for sensitive credentials - Keep mock data in unit tests realistic but simplified
- Document any required environment variables
- Use
-
Async Testing
- Most tests can run async (use
async: true
) - Be cautious with shared resources in integration tests
- Consider using
async: false
for tests that modify global state
- Most tests can run async (use
-
Test Organization
- Follow the established directory structure
- Use appropriate test case modules
- Group related tests in describe blocks
The CI pipeline:
- Runs unit tests first
- Runs integration tests if unit tests pass (TBD, as we didn't add key management in CI yet)
- Uses secure environment variables for API keys
-
Integration Tests Failing
- Check if
test.override.envrc
exists with valid API keys - Verify external service status
- Check rate limits
- Check if
-
Configuration Conflicts
- Ensure you're not running unit and integration tests simultaneously
- Check for conflicting environment variables
-
Mock Issues
- Verify mock data matches expected format
- Check if API responses have changed
- Update mock data as needed
- Check the test output for specific error messages
- Review the relevant test helper modules
- Consult the external service documentation
- Reach out to the team for assistance