JasonBock/Rocks

A mocking library based on the Compiler APIs (Roslyn + Mocks)

C#

394

1,624 commits

updated Oct 9, 2026

See the code

README

Rocks

NuGet

Bugs

Issues

Rocks logo

A mocking library based on the Compiler APIs (Roslyn + Mocks).

Getting Started

Reference the Rocks NuGet package - that's it.

Prerequisites

The Rocks package targets .NET Standard 2.0 for host flexibility. That said, Rocks (as of 10.0.0) will generate code that requires .NET 10.

Usage

To make a mock, you take an interface or an unsealed class that has virtual members:

public interface IAmSimple
{
  void TargetAction();
}

and you use Rocks to create a mock with expectations, along with verifying its usage:

[assembly: Rock(typeof(IAmSimple), BuildType.Create)]

var expectations = new IAmSimpleCreateExpectations();
expectations.Setups.TargetAction();

var mock = expectations.Instance();
mock.TargetAction();

expectations.Verify();

More details can be found on the Overview page.

Additional Documentation

Feedback

If you run into any issues, please add them here.

csharp
csharp-sourcegenerator
mock
mocking
mocking-library
testing

JasonBock/Rocks

A mocking library based on the Compiler APIs (Roslyn + Mocks)

C#

394

1,624 commits

updated Oct 9, 2026

See the code

README

Rocks

NuGet

Bugs

Issues

Rocks logo

A mocking library based on the Compiler APIs (Roslyn + Mocks).

Getting Started

Reference the Rocks NuGet package - that's it.

Prerequisites

The Rocks package targets .NET Standard 2.0 for host flexibility. That said, Rocks (as of 10.0.0) will generate code that requires .NET 10.

Usage

To make a mock, you take an interface or an unsealed class that has virtual members:

public interface IAmSimple
{
  void TargetAction();
}

and you use Rocks to create a mock with expectations, along with verifying its usage:

[assembly: Rock(typeof(IAmSimple), BuildType.Create)]

var expectations = new IAmSimpleCreateExpectations();
expectations.Setups.TargetAction();

var mock = expectations.Instance();
mock.TargetAction();

expectations.Verify();

More details can be found on the Overview page.

Additional Documentation

Feedback

If you run into any issues, please add them here.

csharp
csharp-sourcegenerator
mock
mocking
mocking-library
testing

Project health

NuGet

Latest release

10.3.4 · Sep 29, 2026

Releases this year

8

Significant stargazers

Adam Ralph

427 followers · starred Jun 2017

Wiesław Šoltés

1,000 followers · starred May 2025

Kristian Hellang

906 followers · starred Aug 2015

David Pine

1,024 followers · starred May 2019