Skip to content

coverage: add tests for property, indexer, and method setup edge cases and matching logic#734

Merged
vbreuss merged 1 commit into
mainfrom
topic/add-tests-for-property,-indexer,-and-method-setup-edge-cases-and-matching-logic
Apr 30, 2026
Merged

coverage: add tests for property, indexer, and method setup edge cases and matching logic#734
vbreuss merged 1 commit into
mainfrom
topic/add-tests-for-property,-indexer,-and-method-setup-edge-cases-and-matching-logic

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Apr 30, 2026

This pull request adds comprehensive new unit tests to the Mockolate internal test suite, focusing on improved coverage and correctness for property, indexer, and method setup behaviors. The new tests verify correct handling of edge cases, such as type conversions, storage allocation, and scenario management, as well as ensuring that default and user setups interact as intended.

Property and Setup Management:

  • Added tests to ensure that default property setups do not overwrite user-defined setups and that user setups correctly overwrite defaults in MockRegistry and MockSetups.PropertySetups
  • Introduced tests verifying that the internal property snapshot table in MockRegistry is updated and preserved correctly during property setup operations, including array growth and scenario handling

Indexer and Method Setup Handling:

  • Added tests to ensure that indexer setups correctly handle unknown access types and improper type casting, and that storage allocation for indexer setups is managed correctly and efficiently
  • Added tests for method setups to ensure that querying for the latest or matching setup on empty storage returns null without exceptions (MockSetupsTests.MethodsTests.cs).

Type Conversion and Getter Logic:

  • Introduced tests to verify that property getter logic correctly handles type conversions, including returning stored values when requested as boxed supertypes and handling null references properly

Scenario Management:

  • Added tests ensuring that requesting a scenario with an empty or null name returns the root scenario bucket as expected (MockSetupsTests.cs).

@vbreuss vbreuss self-assigned this Apr 30, 2026
@vbreuss vbreuss added the coverage Additional tests for edge cases or improvement of test coverage label Apr 30, 2026
@vbreuss vbreuss enabled auto-merge (squash) April 30, 2026 19:48
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test Results

    21 files  ±  0      21 suites  ±0   10m 40s ⏱️ + 1m 31s
 3 993 tests + 57   3 991 ✅ + 57  2 💤 ±0  0 ❌ ±0 
25 969 runs  +399  25 965 ✅ +399  4 💤 ±0  0 ❌ ±0 

Results for commit 666459c. ± Comparison against base commit b0d1248.

@vbreuss vbreuss merged commit 0c6032b into main Apr 30, 2026
16 checks passed
@vbreuss vbreuss deleted the topic/add-tests-for-property,-indexer,-and-method-setup-edge-cases-and-matching-logic branch April 30, 2026 19:55
@github-actions
Copy link
Copy Markdown

🚀 Benchmark Results

Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.87GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Event_Mockolate 352.9 ns 3.15 ns 2.63 ns 1.00 0.01 0.1254 0.0005 2.05 KB 1.00
Event_Moq 13,851.4 ns 28.22 ns 22.03 ns 39.26 0.29 0.7324 - 12.51 KB 6.09
Event_NSubstitute 5,194.9 ns 18.38 ns 17.19 ns 14.72 0.11 0.5493 0.0076 9.05 KB 4.40
Event_FakeItEasy 227,656.3 ns 417.24 ns 369.87 ns 645.20 4.69 0.7324 0.4883 15.39 KB 7.49
Event_Imposter 1,380.8 ns 3.38 ns 2.83 ns 3.91 0.03 0.5379 0.0153 8.8 KB 4.29
Event_TUnitMocks 170.2 ns 0.87 ns 0.72 ns 0.48 0.00 0.0837 0.0002 1.37 KB 0.67
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 3.39GHz), 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v4

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Indexer_Mockolate 1 1,092.4 ns 19.42 ns 18.17 ns 1.00 0.02 0.1640 - 4.03 KB 1.00
Indexer_Moq 1 161,517.5 ns 538.23 ns 449.45 ns 147.90 2.42 0.4883 - 20.36 KB 5.05
Indexer_NSubstitute 1 9,554.7 ns 25.66 ns 21.43 ns 8.75 0.14 0.5188 - 12.84 KB 3.18
Indexer_FakeItEasy 1 11,117.1 ns 36.27 ns 32.16 ns 10.18 0.17 0.5646 0.0153 13.87 KB 3.44
Indexer_Imposter 1 971.4 ns 12.98 ns 11.50 ns 0.89 0.02 0.2098 0.0019 5.16 KB 1.28
Indexer_Mockolate 10 2,911.6 ns 15.36 ns 14.37 ns 1.00 0.01 0.2060 - 5.09 KB 1.00
Indexer_Moq 10 171,489.9 ns 638.76 ns 597.49 ns 58.90 0.35 0.9766 0.7324 29.89 KB 5.88
Indexer_NSubstitute 10 22,128.4 ns 42.26 ns 39.53 ns 7.60 0.04 1.0376 0.0305 25.63 KB 5.04
Indexer_FakeItEasy 10 24,014.8 ns 108.05 ns 101.07 ns 8.25 0.05 1.4343 0.0610 35.48 KB 6.98
Indexer_Imposter 10 2,252.5 ns 25.07 ns 23.45 ns 0.77 0.01 0.3242 - 7.97 KB 1.57
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 2.60GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Method_Mockolate 1 446.6 ns 3.80 ns 3.55 ns 1.00 0.01 0.1416 0.0010 2.32 KB 1.00
Method_Moq 1 131,774.7 ns 1,024.52 ns 908.21 ns 295.10 3.00 0.4883 - 14.58 KB 6.28
Method_NSubstitute 1 5,480.3 ns 78.58 ns 73.50 ns 12.27 0.19 0.5569 0.0076 9.12 KB 3.93
Method_FakeItEasy 1 5,586.1 ns 45.50 ns 40.33 ns 12.51 0.13 0.4959 - 8.11 KB 3.50
Method_Imposter 1 563.3 ns 13.01 ns 12.17 ns 1.26 0.03 0.2470 0.0029 4.04 KB 1.74
Method_TUnitMocks 1 719.0 ns 15.35 ns 14.36 ns 1.61 0.03 0.1774 0.0010 2.9 KB 1.25
Method_Mockolate 10 737.0 ns 7.82 ns 7.32 ns 1.00 0.01 0.1545 0.0010 2.53 KB 1.00
Method_Moq 10 138,225.6 ns 1,915.17 ns 1,791.45 ns 187.56 2.96 0.9766 0.7324 18.48 KB 7.30
Method_NSubstitute 10 8,037.2 ns 85.80 ns 80.26 ns 10.91 0.15 0.7324 0.0153 12.07 KB 4.77
Method_FakeItEasy 10 8,688.0 ns 143.79 ns 134.50 ns 11.79 0.21 0.9766 0.0305 16.05 KB 6.34
Method_Imposter 10 1,201.7 ns 10.15 ns 9.00 ns 1.63 0.02 0.3376 0.0057 5.52 KB 2.18
Method_TUnitMocks 10 1,829.6 ns 21.22 ns 19.85 ns 2.48 0.04 0.2747 0.0019 4.49 KB 1.77
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Property_Mockolate 1 565.1 ns 12.85 ns 12.02 ns 1.00 0.03 0.1574 0.0010 2.58 KB 1.00
Property_Moq 1 11,756.9 ns 79.80 ns 74.64 ns 20.81 0.45 0.6104 - 10.27 KB 3.98
Property_NSubstitute 1 7,609.9 ns 26.21 ns 24.52 ns 13.47 0.28 0.6866 - 11.45 KB 4.44
Property_FakeItEasy 1 8,659.7 ns 79.64 ns 70.60 ns 15.33 0.34 0.6866 - 11.24 KB 4.36
Property_Imposter 1 488.8 ns 16.07 ns 15.03 ns 0.87 0.03 0.1912 0.0019 3.13 KB 1.21
Property_TUnitMocks 1 792.8 ns 13.77 ns 12.88 ns 1.40 0.04 0.1526 0.0010 2.51 KB 0.97
Property_Mockolate 10 1,089.6 ns 16.50 ns 13.78 ns 1.00 0.02 0.1869 - 3.07 KB 1.00
Property_Moq 10 18,417.1 ns 138.34 ns 129.41 ns 16.91 0.24 1.0376 - 17.03 KB 5.55
Property_NSubstitute 10 17,188.5 ns 115.61 ns 102.49 ns 15.78 0.21 1.2817 0.0305 21.08 KB 6.87
Property_FakeItEasy 10 20,419.3 ns 82.77 ns 77.42 ns 18.74 0.24 1.8616 - 30.81 KB 10.03
Property_Imposter 10 1,153.4 ns 20.20 ns 17.90 ns 1.06 0.02 0.2842 0.0019 4.67 KB 1.52
Property_TUnitMocks 10 2,223.7 ns 19.68 ns 16.44 ns 2.04 0.03 0.2823 - 4.66 KB 1.52
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 7763 2.45GHz, 1 CPU, 4 logical and 2 physical cores
.NET SDK 10.0.203
[Host] : .NET 10.0.7 (10.0.7, 10.0.726.21808), X64 RyuJIT x86-64-v3

Job=InProcess Toolchain=InProcessEmitToolchain IterationCount=15
LaunchCount=1 WarmupCount=10

Method Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Callback_Mockolate 390.5 ns 1.14 ns 1.01 ns 1.00 0.00 0.1197 - 1.96 KB 1.00
Callback_Moq 97,510.4 ns 241.05 ns 213.68 ns 249.69 0.82 0.4883 0.2441 8.88 KB 4.53
Callback_NSubstitute 4,424.7 ns 6.04 ns 5.65 ns 11.33 0.03 0.4730 0.0076 7.74 KB 3.95
Callback_FakeItEasy 4,805.0 ns 23.34 ns 21.83 ns 12.30 0.06 0.4120 0.0153 6.81 KB 3.47
Callback_Imposter 401.8 ns 4.35 ns 4.07 ns 1.03 0.01 0.1454 0.0010 2.38 KB 1.22
Callback_TUnitMocks 589.1 ns 1.18 ns 1.05 ns 1.51 0.00 0.1602 0.0010 2.63 KB 1.34

@github-actions
Copy link
Copy Markdown

This is addressed in release v3.0.0.

@github-actions github-actions Bot added the state: released The issue is released label Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coverage Additional tests for edge cases or improvement of test coverage state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant