Skip to content

refactor!: do not generate recursive mocks for methods or properties#348

Merged
vbreuss merged 2 commits intomainfrom
topic/donot-generate-recursive-mocks
Jan 6, 2026
Merged

refactor!: do not generate recursive mocks for methods or properties#348
vbreuss merged 2 commits intomainfrom
topic/donot-generate-recursive-mocks

Conversation

@vbreuss
Copy link
Contributor

@vbreuss vbreuss commented Jan 6, 2026

This PR removes the automatic recursive mock generation feature for interface properties and methods. Instead of generating mocks for all interface return types encountered in properties and methods, the generator now only creates mocks for explicitly requested types (with a special exception for HttpClient/HttpMessageHandler).

Key changes

  • Removed recursive traversal of property and method return types when discovering mockable types
  • Updated test expectations to verify that recursive mocks are no longer generated
  • Optimized the processedTypes HashSet initialization by seeding it with initial types

@vbreuss vbreuss self-assigned this Jan 6, 2026
Copilot AI review requested due to automatic review settings January 6, 2026 15:32
@vbreuss vbreuss added the breaking change The changes require a new major version label Jan 6, 2026
@vbreuss vbreuss changed the title refactor!: avoid generating recursive mocks for methods or properties refactor!: do not generate recursive mocks for methods or properties Jan 6, 2026
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the automatic recursive mock generation feature for interface properties and methods. Instead of generating mocks for all interface return types encountered in properties and methods, the generator now only creates mocks for explicitly requested types (with a special exception for HttpClient/HttpMessageHandler).

Key changes:

  • Removed recursive traversal of property and method return types when discovering mockable types
  • Updated test expectations to verify that recursive mocks are no longer generated
  • Optimized the processedTypes HashSet initialization by seeding it with initial types

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
Tests/Mockolate.SourceGenerators.Tests/GeneralTests.cs Updated test name and assertions to verify recursive mock generation no longer occurs
Source/Mockolate.SourceGenerators/MockGeneratorHelpers.cs Removed property and method return type traversal logic; retained special HttpClient handling

@vbreuss vbreuss enabled auto-merge (squash) January 6, 2026 15:33
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

Test Results

    14 files  ±0      14 suites  ±0   5m 36s ⏱️ +14s
 1 825 tests ±0   1 824 ✅ ±0  1 💤 ±0  0 ❌ ±0 
12 172 runs  ±0  12 171 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 55df2d4. ± Comparison against base commit ed2a173.

This pull request removes 2 and adds 2 tests. Note that renamed tests count towards both.
Mockolate.SourceGenerators.Tests.GeneralTests ‑ InterfaceProperty_ShouldRecursivelyCreateMocks
Mockolate.Tests.MockBehaviorTests+DefaultValueTests ‑ Recursive_ShouldReturnMock
Mockolate.SourceGenerators.Tests.GeneralTests ‑ InterfaceProperty_ShouldNotRecursivelyCreateMocks
Mockolate.Tests.MockBehaviorTests+DefaultValueTests ‑ Recursive_ShouldReturnNull

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Jan 6, 2026

🚀 Benchmark Results

Details

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

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

Method Mean Error StdDev Gen0 Gen1 Allocated
Simple_Mockolate 1.541 μs 0.0176 μs 0.0165 μs 0.2270 - 3.72 KB
Simple_Moq 178.907 μs 0.6876 μs 0.5742 μs 0.4883 - 14.55 KB
Simple_NSubstitute 5.777 μs 0.0426 μs 0.0398 μs 0.5569 0.0076 9.14 KB
Simple_FakeItEasy 6.608 μs 0.1159 μs 0.1084 μs 0.4959 - 8.11 KB

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 6, 2026

@vbreuss vbreuss merged commit 493efc4 into main Jan 6, 2026
12 checks passed
@vbreuss vbreuss deleted the topic/donot-generate-recursive-mocks branch January 6, 2026 15:42
@github-actions
Copy link

github-actions bot commented Jan 6, 2026

This is addressed in release v0.49.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change The changes require a new major version state: released The issue is released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider not automatically generating mocks for all properties/method return values

2 participants