Testing Guide
This guide covers how to run tests in the Bark project. All tests are managed using just, which comes preinstalled with the Nix flake.
Prerequisites
Before running tests, make sure you have:
- Set up your development environment (see Contributing Guide)
- Installed
just (comes with Nix, or install manually)
- PostgreSQL binaries available (
initdb, pg_ctl)
- For integration tests:
bitcoind and lightningd with hold plugin
Test Commands
Pre-commit Checks
Run all pre-commit checks (style checks + cargo check):
This runs:
- Style prechecks (indentation, whitespace, etc.)
cargo check on all packages and tests
Individual Prechecks
Run specific style checks:
This includes:
rust_no_spaces_for_indent - Enforce tabs for indentation
rust_no_whitespace_on_empty_lines - No trailing whitespace
unused_server_logs - Detect unused log statements
conflicting_migration_scripts - Check for migration conflicts
Unit Tests
Run all unit tests (excludes integration tests):
just test-unit
# or shorter alias
just unit
Run a specific unit test:
Example:
just unit test_vtxo_validation
Integration Tests
Never run integration tests with cargo test directly. They require environment variables set by just.
Run all integration tests (uses bitcoind backend by default):
just test-integration
# or shorter alias
just int
Run a specific integration test:
Example:
Client-Only Integration Tests
Run integration tests for bark, movement, exit and lightning test files only:
just test-integration-client
# or shorter alias
just int-client
Esplora Backend Tests
Run integration tests using Esplora as the chain source:
just test-integration-esplora
# or shorter alias
just int-esplora
Run a specific test with Esplora:
just int-esplora <test-name>
Mempool Backend Tests
Run integration tests using Mempool.space as the chain source:
just test-integration-mempool
# or shorter alias
just int-mempool
Run a specific test with Mempool:
just int-mempool <test-name>
All Tests
Run the complete test suite (unit + integration with all backends):
This runs:
- Unit tests
- Integration tests (bitcoind)
- Integration tests (Esplora)
- Integration tests (Mempool)
Code Coverage
Build with Coverage
Build the project with code coverage instrumentation:
Unit Tests with Coverage
Integration Tests with Coverage
just test-integration-codecov
# or shorter alias
just int-cov
With Esplora:
just test-integration-esplora-codecov
With Mempool:
just test-integration-mempool-codecov
All Tests with Coverage
Generate Coverage Report
After running tests with coverage, generate an HTML report:
The report will be available at ./target/debug/codecov/index.html.
Build Commands
Development Build
Build all workspace crates:
Check Without Building
Run cargo check on all packages:
Commit Checks
Verify that all commits individually compile:
macOS
On macOS, Core Lightning runs inside Docker. Make sure:
- Docker is installed and running
- “Host networking” feature is enabled in Docker Desktop
- Set the Docker image environment variable if not using Nix:
export LIGHTNINGD_DOCKER_IMAGE="second/cln-hold:v25.02.2"
Linux
Linux uses native lightningd binaries. Ensure the hold plugin is in your PATH or set:
export LIGHTNINGD_EXEC="${PATH_TO_LIGHTNINGD}/bin/lightningd"
export HOLD_INVOICE_PLUGIN="/hold/target/debug/hold"
Common Test Patterns
Running Tests in Watch Mode
While just doesn’t have built-in watch mode, you can use cargo-watch:
cargo install cargo-watch
cargo watch -x "nextest run --workspace --exclude ark-testing"
Running Tests for a Specific Package
cargoNextest run --package bark-wallet
Running Tests Matching a Pattern
This runs all unit tests with “lightning” in the name.
Verbose Test Output
For more detailed test output:
cargo nextest run --no-fail-fast --workspace --exclude ark-testing --nocapture
Troubleshooting
PostgreSQL Connection Issues
If tests fail with PostgreSQL connection errors:
- Using test managed host: Ensure
initdb and pg_ctl are in your PATH or set POSTGRES_BINS
- Using external host: Verify
TEST_POSTGRES_HOST points to a running PostgreSQL instance with correct credentials
Lightning Tests Failing
- Verify
lightningd is in your PATH or LIGHTNINGD_EXEC is set
- Check that the hold plugin is available
- On macOS, ensure Docker is running
Bitcoin Tests Failing
- Ensure
bitcoind is in your PATH or BITCOIND_EXEC is set
- Verify you have enough disk space for test chains
Test Timeouts
Integration tests can take time to set up bitcoind and lightningd. If tests timeout:
- Run tests individually to isolate the issue
- Check system resources (CPU, memory)
- Look for test-specific logs in the output
Best Practices
- Run
just checks before committing - Catches style and compilation issues early
- Test your changes across all backends - Use
just test to ensure compatibility
- Write focused tests - Unit tests should be fast and isolated
- Integration tests should test real workflows - Set up realistic scenarios
- Keep test data minimal - Only include what’s necessary for the test
Next Steps