Blog
Boost Your Solana Development with the New Anchor Code Coverage Tool

Boost Your Solana Development with the New Anchor Code Coverage Tool

Blockchain Explained

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:

  • Enable code coverage generation for your Anchor project.
  • Generate code coverage directly from your existing TypeScript tests within LiteSVM.
  • Integrate the new withCoverage function into your testing workflow.
  • Generate a comprehensive coverage report that pinpoints untested areas.

Let’s get down to it.

Speach Bubble IllustrationGlow Blog Banner

Your Step-by-Step Guide to Solana Code Coverage

1. Enabling Coverage

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.

2. Generate Coverage

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.

3. Generate Report

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.

Watch the Demo

To see all of these steps in action, check out our quick demo video:

Speach Bubble Illustration
Contact Us
Glow Blog Banner

Build, Explore, Expand

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!

Drop us a line.

Or just shoot us a message on Telegram

Select Contact Method
Looking for

Thank you! Your submission has been received!

Oops! Something went wrong while submitting the form.
Mail Box IllustrationCube Illustration 2