A mocking library based on the Compiler APIs (Roslyn + Mocks)
Reference the Rocks
NuGet package - that's it.
The Rocks package targets .NET Standard 2.0 for host flexibility. That said, Rocks (as of 9.0.0
) will generate code that requires .NET 9.
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.Methods.TargetAction();
var mock = expectations.Instance();
mock.TargetAction();
expectations.Verify();
More details can be found on the Overview page.
- Discord Server
- Changelog
- Unit testing best practices with .NET Core and .NET Standard
- BenchmarkMockNet
If you run into any issues, please add them here.