Skip to content

ecoAPM/BenchmarkMockNet

Repository files navigation

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!

  • 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 8

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/net8.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