Use unit tests for regular development. Only run integration tests when explicitly needed or when making changes to integration/end-to-end functionality.
Test Types Overview
Graph Node uses three types of tests:- Unit Tests: Fast, focused tests inlined with source code
- Runner Tests: Medium-speed integration-style tests for subgraph execution
- Integration Tests: Full end-to-end tests with real services
Unit Tests
Unit tests are inlined with the source code and test individual functions and modules in isolation.Prerequisites
1
Start PostgreSQL
PostgreSQL must be running on Or manually:
localhost:5432 with an initialized graph-test database.Using Process Compose (recommended):2
Start IPFS
IPFS must be running on
localhost:5001.3
Install Additional Tools
Install PNPM and Foundry:
4
Set Environment Variable
Running Unit Tests
Unit Test Best Practices
- Write unit tests for all new functions and modules
- Keep tests focused on a single behavior
- Use descriptive test names that explain what is being tested
- Mock external dependencies when possible
- Tests should be fast (< 1 second each)
Runner Tests
Runner tests are integration-style tests that test subgraph execution with real services but in a controlled environment.Prerequisites
Runner tests use the same prerequisites as unit tests:- PostgreSQL running on
localhost:5432(with initializedgraph-testdatabase) - IPFS running on
localhost:5001 - PNPM installed
- Foundry installed
- Environment variable
THEGRAPH_STORE_POSTGRES_DIESEL_URLset
Runner tests use the same Nix services stack as unit tests:
Running Runner Tests
Runner Test Characteristics
- Take moderate time (10-20 seconds)
- Automatically reset the database between runs
- Some tests can pass without IPFS, but tests involving file data sources require it
- Test real subgraph execution with compiled WASM
Integration Tests
Integration tests run Graph Node with real blockchain nodes and test the complete indexing pipeline.Prerequisites
1
Start PostgreSQL
PostgreSQL must be running on
localhost:3011 with an initialized graph-node database.Using Process Compose (recommended):2
Start IPFS
IPFS must be running on
localhost:3001.Included in Process Compose setup above.3
Start Anvil
Anvil (Ethereum test chain) must be running on
localhost:3021.Included in Process Compose setup above.4
Install Tools
Install PNPM and Foundry as described in the unit tests section.
Running Integration Tests
Integration Test Verification
Integration Test Logs
Logs are written totests/integration-tests/graph-node.log for debugging:
Service Configuration
Port Mapping
Process Compose Services
The repository includes Process Compose configurations for managing test services:Code Quality Checks
Running Quality Checks
1
Format Code
2
Lint Code
3
Check Release Build
cargo check alone might miss.4
Run Tests
Development Workflow
Continuous Testing During Development
Usecargo-watch to automatically run checks during development:
- Format all source files
- Check for compilation errors
- Run tests
- Generate documentation
Test-Driven Development
1
Write Test First
Write a failing test that describes the desired behavior:
2
Run Test to Verify Failure
3
Implement Feature
Write the minimum code needed to make the test pass.
4
Run Test to Verify Success
5
Run All Quality Checks
Testing Specific Components
Testing Store Changes
Testing Chain Adapters
Testing GraphQL
Debugging Tests
View Test Output
Run Tests in Serial
Debug with RUST_LOG
Common Test Issues
Database Connection Errors
IPFS Connection Errors
Test Timeout Issues
Best Practices
1
Write Tests First
Use test-driven development: write tests before implementation.
2
Keep Tests Fast
Unit tests should be fast. Move slow tests to runner or integration tests.
3
Test Edge Cases
Test boundary conditions, error cases, and unusual inputs.
4
Use Descriptive Names
Test names should clearly describe what is being tested.
5
Clean Up Resources
Ensure tests clean up after themselves (database, files, etc.).
6
Verify Test Coverage
Use
cargo tarpaulin or similar tools to check test coverage.
