Skip to content

coverage: add missing tests for Sources.MockClass.cs#727

Merged
vbreuss merged 2 commits into
mainfrom
topic/cleanup-source-generators
Apr 30, 2026
Merged

coverage: add missing tests for Sources.MockClass.cs#727
vbreuss merged 2 commits into
mainfrom
topic/cleanup-source-generators

Conversation

@vbreuss
Copy link
Copy Markdown
Member

@vbreuss vbreuss commented Apr 30, 2026

This pull request adds tests for new language features and improved error handling for unsupported method signatures.

Support for static abstract members and explicit implementations:

  • Added tests to ensure that when interfaces declare static abstract methods or properties with colliding names in base and derived interfaces, the generated code emits explicit static implementations with the static keyword preserved.
  • Added a test to verify that static abstract methods with parameters correctly append arguments to the fast buffer, ensuring proper interaction recording.
  • Added a test to confirm that when a concrete base class is combined with an interface declaring static abstract members, the generated constructor primes the MockRegistryProvider so that virtual calls during base-class construction can resolve the registry.

Improved handling and validation for ref struct methods:

  • Added tests to ensure that methods returning a non-span ref struct or using out/ref ref struct parameters throw NotSupportedException and skip setup surface generation, preventing unsupported ref struct signatures from being used in the setup pipeline.

Source generator code and overloads:

  • Refactored the generator code to require non-null constructor lists for overload generation, simplifying the logic in AppendTypedCreateMockOverloads.
  • Removed an unnecessary constructor overload and related code for cases where no constructors are present, streamlining the generated code.

@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 15:03
@sonarqubecloud
Copy link
Copy Markdown

@github-actions
Copy link
Copy Markdown

Test Results

    21 files  ± 0      21 suites  ±0   11m 10s ⏱️ + 1m 37s
 3 866 tests + 6   3 864 ✅ + 6  2 💤 ±0  0 ❌ ±0 
25 112 runs  +18  25 108 ✅ +18  4 💤 ±0  0 ❌ ±0 

Results for commit 49f55e0. ± Comparison against base commit c12680a.

@vbreuss vbreuss merged commit 7729e9d into main Apr 30, 2026
16 checks passed
@vbreuss vbreuss deleted the topic/cleanup-source-generators branch April 30, 2026 15:09
@github-actions
Copy link
Copy Markdown

🚀 Benchmark Results

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
Event_Mockolate 340.5 ns 4.40 ns 3.90 ns 1.00 0.02 0.1254 0.0005 2.05 KB 1.00
Event_Moq 16,223.8 ns 180.62 ns 150.83 ns 47.66 0.68 0.7324 - 12.73 KB 6.19
Event_NSubstitute 5,641.9 ns 74.77 ns 69.94 ns 16.57 0.27 0.5493 0.0076 9.05 KB 4.40
Event_FakeItEasy 214,029.4 ns 2,340.60 ns 2,074.88 ns 628.70 9.08 0.7324 0.4883 15.39 KB 7.49
Event_Imposter 1,462.7 ns 36.78 ns 34.41 ns 4.30 0.11 0.5379 0.0153 8.8 KB 4.29
Event_TUnitMocks 188.0 ns 3.19 ns 2.82 ns 0.55 0.01 0.0837 0.0002 1.37 KB 0.67
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
Indexer_Mockolate 1 1.001 μs 0.0207 μs 0.0193 μs 1.00 0.03 0.2460 0.0019 4.03 KB 1.00
Indexer_Moq 1 218.268 μs 1.3739 μs 1.2179 μs 218.02 4.32 0.9766 0.4883 20.45 KB 5.07
Indexer_NSubstitute 1 9.390 μs 0.1402 μs 0.1312 μs 9.38 0.22 0.7782 - 12.78 KB 3.17
Indexer_FakeItEasy 1 12.167 μs 0.2209 μs 0.2066 μs 12.15 0.31 0.8392 0.0305 13.88 KB 3.44
Indexer_Imposter 1 1.022 μs 0.0366 μs 0.0342 μs 1.02 0.04 0.3147 0.0038 5.16 KB 1.28
Indexer_Mockolate 10 2.552 μs 0.0543 μs 0.0508 μs 1.00 0.03 0.3090 - 5.09 KB 1.00
Indexer_Moq 10 228.666 μs 1.4741 μs 1.3789 μs 89.65 1.80 1.7090 1.4648 29.97 KB 5.89
Indexer_NSubstitute 10 22.845 μs 0.1585 μs 0.1482 μs 8.96 0.18 1.5564 0.0305 25.58 KB 5.03
Indexer_FakeItEasy 10 25.762 μs 0.2580 μs 0.2413 μs 10.10 0.21 2.1667 0.0610 35.47 KB 6.97
Indexer_Imposter 10 2.321 μs 0.0458 μs 0.0429 μs 0.91 0.02 0.4845 0.0076 7.97 KB 1.57
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
AMD EPYC 9V74 3.69GHz, 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
Method_Mockolate 1 365.1 ns 9.78 ns 8.67 ns 1.00 0.03 0.1416 0.0010 2.32 KB 1.00
Method_Moq 1 103,856.7 ns 980.31 ns 869.02 ns 284.63 6.85 0.7324 0.4883 14.59 KB 6.29
Method_NSubstitute 1 4,364.3 ns 26.09 ns 24.40 ns 11.96 0.28 0.5569 0.0076 9.12 KB 3.93
Method_FakeItEasy 1 4,636.1 ns 90.54 ns 84.70 ns 12.71 0.37 0.4959 - 8.11 KB 3.50
Method_Imposter 1 462.1 ns 19.65 ns 17.42 ns 1.27 0.05 0.2470 0.0033 4.04 KB 1.74
Method_TUnitMocks 1 552.9 ns 7.52 ns 6.67 ns 1.52 0.04 0.1774 0.0010 2.9 KB 1.25
Method_Mockolate 10 593.8 ns 18.26 ns 17.08 ns 1.00 0.04 0.1545 0.0010 2.53 KB 1.00
Method_Moq 10 105,376.4 ns 1,114.11 ns 930.33 ns 177.60 5.14 1.0986 0.9766 18.48 KB 7.30
Method_NSubstitute 10 6,242.2 ns 91.35 ns 80.98 ns 10.52 0.32 0.7324 0.0153 12.07 KB 4.77
Method_FakeItEasy 10 7,105.4 ns 189.54 ns 177.30 ns 11.98 0.44 0.9766 0.0153 16.05 KB 6.34
Method_Imposter 10 970.5 ns 33.97 ns 31.78 ns 1.64 0.07 0.3376 0.0057 5.52 KB 2.18
Method_TUnitMocks 10 1,496.0 ns 29.70 ns 27.79 ns 2.52 0.08 0.2747 0.0019 4.49 KB 1.77
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 N Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Property_Mockolate 1 557.2 ns 7.95 ns 7.43 ns 1.00 0.02 0.1574 0.0010 2.58 KB 1.00
Property_Moq 1 10,581.9 ns 55.36 ns 49.08 ns 18.99 0.26 0.6104 - 10.53 KB 4.09
Property_NSubstitute 1 7,010.3 ns 124.23 ns 116.20 ns 12.58 0.26 0.6943 0.0076 11.45 KB 4.44
Property_FakeItEasy 1 7,296.9 ns 161.24 ns 150.82 ns 13.10 0.31 0.6866 - 11.24 KB 4.36
Property_Imposter 1 432.4 ns 4.46 ns 4.17 ns 0.78 0.01 0.1912 0.0019 3.13 KB 1.21
Property_TUnitMocks 1 741.2 ns 6.71 ns 6.28 ns 1.33 0.02 0.1526 0.0010 2.51 KB 0.97
Property_Mockolate 10 1,029.1 ns 7.00 ns 6.55 ns 1.00 0.01 0.1869 - 3.07 KB 1.00
Property_Moq 10 16,530.8 ns 157.61 ns 147.43 ns 16.06 0.17 1.0986 - 18.42 KB 6.00
Property_NSubstitute 10 15,525.0 ns 91.64 ns 81.24 ns 15.09 0.12 1.2817 0.0305 21.08 KB 6.87
Property_FakeItEasy 10 17,274.6 ns 285.06 ns 266.65 ns 16.79 0.27 1.8616 - 30.81 KB 10.03
Property_Imposter 10 1,055.2 ns 10.00 ns 8.86 ns 1.03 0.01 0.2842 0.0019 4.67 KB 1.52
Property_TUnitMocks 10 2,246.3 ns 12.25 ns 10.23 ns 2.18 0.02 0.2823 - 4.66 KB 1.52
Details

BenchmarkDotNet v0.15.8, Linux Ubuntu 24.04.4 LTS (Noble Numbat)
Intel Xeon Platinum 8370C CPU 2.80GHz (Max: 2.79GHz), 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 Mean Error StdDev Ratio RatioSD Gen0 Gen1 Allocated Alloc Ratio
Callback_Mockolate 469.8 ns 6.96 ns 6.51 ns 1.00 0.02 0.0796 0.0005 1.96 KB 1.00
Callback_Moq 71,112.4 ns 544.95 ns 509.75 ns 151.40 2.31 0.2441 - 8.88 KB 4.53
Callback_NSubstitute 4,314.2 ns 14.53 ns 13.59 ns 9.18 0.13 0.3128 0.0076 7.74 KB 3.95
Callback_FakeItEasy 4,755.3 ns 15.80 ns 14.78 ns 10.12 0.14 0.2747 - 6.8 KB 3.47
Callback_Imposter 461.9 ns 9.96 ns 9.31 ns 0.98 0.02 0.0968 0.0005 2.38 KB 1.22
Callback_TUnitMocks 724.9 ns 10.10 ns 9.45 ns 1.54 0.03 0.1068 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