Home

Awesome

BenchmarkMockNet

This repo contains the code for, and results of, a series of performance benchmarks running against various .NET mocking libraries, using BenchmarkDotNet.

Results CI Coverage

Maintainability Rating Reliability Rating Security Rating

Current contenders (alphabetical order)

The baseline is a simple stub class.

Want to add more? PRs welcome!

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

TestHow long does it take...
Constructionfor a mock to be created?
Returnfor a mocked method to return a value?
EmptyReturnfor a mocked method to return default?
EmptyMethodfor a mocked method to be called?
OneParameterfor a mocked method to be called with a parameter?
Callbackfor a mocked method to perform a callback?
Verifyfor 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

Installation

  1. Run dotnet restore to install all dependent libraries and prep for build
  2. Run dotnet publish -c Release to build the benchmarks (the -c Release flag is important to maximize accuracy)

Usage

  1. Once restored and built, run dotnet bin/Release/net9.0/publish/BenchmarkMockNet.dll to execute the benchmarks
  2. Benchmarks will take about 5 minutes to run
  3. Results are stored in the BenchmarkDotNet.Artifacts directory, in both HTML and Markdown formats