Awesome
BenchmarkMockNet
This repo contains the code for, and results of, a series of performance benchmarks running against various .NET mocking libraries, using BenchmarkDotNet.
Current contenders (alphabetical order)
The baseline is a simple stub class.
Want to add more? PRs welcome!
- Add a method named after the framework to
IMockingBenchmark
IMockingBenchmark<T>
MockingBenchmark
MockingBenchmark<T>
- Implement it in each of classes in the
Benchmarks
directory - Add a reference to it in
All.Frameworks
A note about PCLMock
PCLMock
is a little different than the other libraries tested here, in that it requires explicitly generated mock classes. Compared against the other contenders, which use underlying parts of the framework like reflection to mock classes more "on the fly", PCLMock
boasts improved performance over its more dynamic counterparts, at the cost of some additional effort during development time.
Tests
These tests cover standard mocking framework functionality
Test | How long does it take... |
---|---|
Construction | for a mock to be created? |
Return | for a mocked method to return a value? |
EmptyReturn | for a mocked method to return default? |
EmptyMethod | for a mocked method to be called? |
OneParameter | for a mocked method to be called with a parameter? |
Callback | for a mocked method to perform a callback? |
Verify | for verification that a method was called? |
Want to add more? PRs welcome! Add a new class extending MockingBenchmark
or MockingBenchmark<T>
, depending on what you're testing, and a test case to BenchmarkTests
with the relevant assertion.
Results
Latest official results from the GitHub Actions workflow are available on the Results page.
Building/Running from source
Requirements
- .NET SDK
Installation
- Run
dotnet restore
to install all dependent libraries and prep for build - Run
dotnet publish -c Release
to build the benchmarks (the-c Release
flag is important to maximize accuracy)
Usage
- Once restored and built, run
dotnet bin/Release/net9.0/publish/BenchmarkMockNet.dll
to execute the benchmarks - Benchmarks will take about 5 minutes to run
- Results are stored in the
BenchmarkDotNet.Artifacts
directory, in both HTML and Markdown formats