Solana for Developers
Writing Program Tests in Rust

Overview: Writing Program Tests in Rust

A high-level overview of what you will learn in this module

Until now you have deployed programs directly and manually verified behavior. That approach breaks down fast: every change risks a regression, and catching mistakes on Devnet costs real time and dev SOL. Automated tests solve both problems.

In this module you will write integration tests for the voting program you built in the last module. The tests run against a full Solana runtime inside your process, with no external cluster or CLI required.

What is solana-program-test?

solana-program-test is a crate that spins up a lightweight Solana validator in memory. It gives you a BanksClient, which is a client interface for submitting transactions and reading account data, the same operations a real client would perform on Devnet, but entirely local and deterministic.

Because the validator runs inside the test process, you can:

  • Warp the clock forward to any slot to test time-dependent logic without actually waiting.
  • Fund arbitrary keypairs with as much SOL as you need.
  • Inspect account data directly after each instruction, without needing a frontend or RPC call.

Module Goals

By the end of this module you will know how to:

  • Set up solana-program-test as a dev dependency and configure your project for testing.
  • Write reusable helper functions for funding accounts and submitting transactions.
  • Build instruction helper functions that derive PDAs and assemble account lists on behalf of the test.
  • Write happy-path tests that assert on deserialized account state.
  • Write negative tests that confirm your program rejects invalid inputs with the correct errors.
  • Use warp_to_slot to simulate time passing and test slot-based constraints.

Last updated on