By
Andrea Candela
July 24, 2025
3 minutes
Every developer worth his/her salt is keenly aware that even a tiny oversight in your code can lead to massive headaches, security vulnerabilities, or significant financial losses. Untested code isn't just inefficient – it's a security risk waiting for an exploit. And since our team is constantly building within the Anchor framework, we wanted to create a more efficient way to improve the quality and security of our code and accelerate debugging cycles.
That's why we created the first of its kind Solana code coverage tool for Anchor projects that generates comprehensive code coverage directly from your existing TypeScript tests within LiteSVM and provides detailed coverage reports that help you identify untested areas, significantly improving the quality and security of your work.
In this blog post, we'll cover how to:
withCoverage
function into your testing workflow.Let’s get down to it.
The first step is to enable code coverage in your Anchor project. It's straightforward - you just need to add these seven lines of Rust to your project's configuration.
#[cfg(not(target_os = "solana"))]
mod coverage {
use super::*;
use anchor_lang::solana_program::program_stubs::{set_syscall_stubs, SyscallStubs};
use anchor_lang::solana_program::{entrypoint::ProgramResult, instruction::Instruction};
// call coverage macro
solana_coverage::anchor_coverage!();
}
Once you've added these lines, simply open your terminal, navigate to your project directory, and type anchor build
And just like that, your project is ready to start tracking every line of code.
With coverage enabled, generating a report is even easier.
Simply open your text editor, navigate to your test file, and write svm.withCoverage
to the before function. Then, you just type anchor coverage
While LiteSVM runs in the background you’ll continue to see you regular test output from your TypeScript tests.
Once your tests are complete, the tool automatically generates an HTML report.
You’ll see an overall summary of your coverage - including lines and branches. And if you click on the Filename (which we highly recommend you do!), you can drill down into individual lines of code.
Green lines mean your tests covered that code, while red lines highlight untested areas. This allows you to pinpoint exactly where you need to add more tests to improve the quality and security of your code.
To see all of these steps in action, check out our quick demo video:
At LimeChain, our purpose is to build, explore, and expand blockchain solutions that create value for leaders and organizations. We believe this Solana Code Coverage Tool is a game-changer for Anchor developers, empowering you to build more secure, robust, and reliable Solana programs. We're incredibly excited to see what you build with it.
Head over to our GitHub repository to get started, contribute, and help us make the Solana ecosystem even stronger.
Thanks for watching, and happy building!