Testing Basics
8 examples to get you started with Solana program testing - 5 basic and 3 intermediate. Covers the testing pyramid: LiteSVM 0.6.x unit tests, Mollusk instruction tests, Anchor TS integration, and validator E2E.
Search across all documentation pages
8 examples to get you started with Solana program testing - 5 basic and 3 intermediate. Covers the testing pyramid: LiteSVM 0.6.x unit tests, Mollusk instruction tests, Anchor TS integration, and validator E2E.
anchor test configured.@solana/kit 7.0.0 for client-side tests.anchor --version # 0.32.1
cargo test --versionDefault integration test spins local validator.
anchor testtests/*.ts.Anchor.toml.Related: Anchor TS Tests
In-process SVM without validator process.
use litesvm::LiteSVM;
use solana_sdk::{signature::Keypair, signer::Signer, transaction::Transaction};
let mut svm = LiteSVM::new();
let payer = Keypair::new();
svm.airdrop(&payer.pubkey(), 1_000_000_000).unwrap();.so with svm.add_program.Related: LiteSVM
Lightweight instruction-level runner in Rust tests.
use mollusk_svm::Mollusk;
use solana_sdk::instruction::{AccountMeta, Instruction};
let mollusk = Mollusk::new(&program_id, "target/deploy/my_program");
let ix = Instruction { program_id, accounts: vec![], data: vec![] };
mollusk.process_instruction(&ix, &accounts);Related: Mollusk
Negative tests are mandatory for security.
try {
await program.methods.badWithdraw().rpc();
throw new Error("expected fail");
} catch (e) {
// expect anchor error code
}#[error_code] enum.Related: Sealevel Attacks Catalog
Deterministic CI requires clean ledger.
solana-test-validator --reset --quiet &
anchor test --skip-local-validator--reset clears state between runs.Related: Testing Against a Validator
Client and program must agree on seeds.
const [pda] = PublicKey.findProgramAddressSync(
[Buffer.from("vault"), user.toBuffer()],
program.programId
);
const account = await program.account.vault.fetch(pda);b"vault" vs "vault").Related: Testing CPIs & PDAs
DeFi tests need mainnet pool state.
surfpool start --rpc-url https://api.mainnet-beta.solana.com
export ANCHOR_PROVIDER_URL=http://127.0.0.1:8899
anchor test --skip-local-validatorProperty tests find overflow edges.
cargo fuzz run deposit_fuzz -- -max_total_time=300Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, anchor-lang 0.32.1, Rust 1.91.1, @solana/kit 7.0.0, Surfpool 0.12.0, and LiteSVM 0.6.x.
Reviewed by Chris St. John·Last updated Jul 19, 2026