Uh oh!
There was an error while loading. Please reload this page.
[Test Improver] Add unit tests for LoggingManager.BuildAsync - #8104
Conversation
Tests cover: - AddProvider with null throws ArgumentNullException - BuildAsync with no providers returns empty factory - Factory delegate receives correct LogLevel and IServiceProvider - Non-IExtension provider is always included - Enabled IExtension provider is included - Disabled IExtension provider is excluded - IAsyncInitializableExtension provider has InitializeAsync called - Disabled IAsyncInitializableExtension provider does not have InitializeAsync called Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Amaury Levé (Evangelink)
left a comment
There was a problem hiding this comment.
Summary
Workflow: PR Nitpick Reviewer 🔍
Date: 2026-05-11
Repository: microsoft/testfx
Key Findings
Good addition of unit tests for LoggingManager.BuildAsync — the coverage is thorough, covering no providers, enabled/disabled extension providers, and initializable providers. A few minor consistency issues worth addressing:
- Important — Mock naming inconsistency: Class-level fields use
_mockXxxprefix while local test variables usexxxMocksuffix. Picking one convention for the whole file improves readability. - Minor — Silent discard of
CreateLoggerreturn value (lines 72, 89, 104): Using_ = factory.CreateLogger(...)makes the intentional discard explicit. - Minor —
Returns(Task.CompletedTask)vsReturnsAsync()(line 115): All other async setups useReturnsAsync(...); a small inconsistency worth aligning.
Positive Highlights
- Excellent use of helper test interfaces at the bottom of the file to combine
ILoggerProvider,IExtension, andIAsyncInitializableExtension— clean and reusable. - Test method names are descriptive and follow the
Method_Condition_ExpectedResultpattern consistently. - Good use of
Times.Once/Times.Neverfor precise mock verification.
Generated by PR Nitpick Reviewer
🔍 Meticulously inspected by PR Nitpick Reviewer 🔍
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Pull request overview
Adds unit tests for Microsoft.Testing.Platform.Logging.LoggingManager.BuildAsync, which builds the platform ILoggerFactory by evaluating provider factories, filtering disabled extensions, and initializing async-initializable providers.
Changes:
- Added a new
LoggingManagerTestssuite covering null guards, provider inclusion/exclusion, and initialization behavior. - Introduced lightweight internal marker interfaces in the test file to mock combinations of
ILoggerProvider+IExtension+IAsyncInitializableExtension.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs | Adds new unit tests targeting LoggingManager.BuildAsync behaviors around provider creation, extension enablement filtering, and async initialization. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 2
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Amaury Levé (Evangelink)
left a comment
There was a problem hiding this comment.
Summary
Workflow: Test Expert Reviewer 🧪
Date: 2026-05-11
Repository: microsoft/testfx
Key Findings
[Assertion] Near-tautological assertion in
BuildAsync_WithNoProviders_ReturnsEmptyLoggerFactory(line 36):Assert.IsNotNull(factory)can never fail sinceBuildAsyncalways constructs a newLoggerFactory. The test doesn't verify the "empty" behavior its name implies.[Coverage] Missing test for enabled
IExtensionInitializableLoggerProvider(line 126): The disabled case is tested, but there's no test for whenIsEnabledAsync()returnstrueon a provider that implements bothIExtensionandIAsyncInitializableExtension. The production code has a distinct path where such a provider must be included AND haveInitializeAsync()called — currently uncovered.
What's Well Done
- Good isolation: fresh mock instances per test class instance, no static mutable state
- The factory-delegate capture pattern in
BuildAsync_PassesLogLevelAndServiceProviderToFactoryis clean and effective - Correct use of
Times.Neverto verify exclusion paths - Helper interfaces at the bottom of the file (
IExtensionLoggerProvider,IInitializableLoggerProvider,IExtensionInitializableLoggerProvider) are a good pattern for multi-interface mocking without polluting production code
Recommendations
- Strengthen the no-providers test to actually exercise the factory (e.g., call
factory.CreateLogger("test")and verify a logger is returned without throwing) - Add
BuildAsync_WithEnabledInitializableExtensionProvider_IncludesAndInitializesProviderto cover the enabled + initializable extension path
Generated by Test Expert Reviewer
🧪 Test quality reviewed by Test Expert Reviewer 🧪
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Amaury Levé (Evangelink)
left a comment
There was a problem hiding this comment.
Summary
Workflow: Expert Code Reviewer
Date: 2026-05-11
Repository: microsoft/testfx
Review Scope
Single file added: test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs — 144 lines of unit tests for the internal LoggingManager.BuildAsync method.
Analysis
I reviewed the test code against the production logic in LoggingManager.BuildAsync and the supporting types (LoggerFactory, TryInitializeAsync, IExtension, IAsyncInitializableExtension).
Correctness ✅ All 8 tests accurately model the production branching logic:
- The disabled-provider guard (
IExtension.IsEnabledAsync()) is correctly exercised by tests 5, 6, and 8, each with properly-configuredIsEnabledAsyncmock setup so noawait nullrisk. - The initialization path (
IAsyncInitializableExtension.InitializeAsync()viaTryInitializeAsync) is correctly targeted by tests 7 and 8. - The
Times.Once/Times.Neververifications are sound — they would catch bugs in both directions.
Mock setup ✅ All mocks that implement IExtension have IsEnabledAsync() explicitly set up, avoiding the await null footgun from Moq's loose default for Task-returning members.
Threading ✅ _mockMonitor.Lock(...) is correctly wired to return a disposable, satisfying the using block in LoggerFactory.CreateLogger.
IDisposable — ILoggerFactory instances are not disposed after use, but this is inconsequential since all providers are mock objects with no real resources; no improvement needed here.
Internal interfaces — The three internal marker interfaces (IExtensionLoggerProvider, IInitializableLoggerProvider, IExtensionInitializableLoggerProvider) are a clean test-local pattern consistent with the existing IDisposableLoggerProvider in LoggerFactoryTests.cs.
Key Findings
No correctness, threading, performance, API compatibility, or security issues found.
Generated by Expert Code Reviewer 🧠
🧠 Reviewed by Expert Code Reviewer 🧠
Amaury Levé (Evangelink)
commented
May 11, 2026
Copilot address review comments |
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
All review comments were addressed in the previous commit: mock naming standardized ( |
Amaury Levé (Evangelink)
commented
May 11, 2026
Copilot resolve the merge conflicts in this pull request |
Amaury Levé (Evangelink)
commented
May 11, 2026
Copilot resolve the merge conflicts in this pull request |
…Tests.cs Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
…Tests.cs Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Merge conflicts resolved. The add/add conflict in |
Already resolved in the previous commit — the add/add conflict in |
Amaury Levé (Evangelink)
commented
May 11, 2026
Copilot fix issues azure-pipelines test\UnitTests\MSTestAdapter.PlatformServices.UnitTests\Services\DesktopTestSourceHostTests.cs(107,57): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type. azure-pipelines test\UnitTests\MSTestAdapter.PlatformServices.UnitTests\Services\DesktopTestSourceHostTests.cs(164,57): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type. azure-pipelines test\UnitTests\MSTestAdapter.PlatformServices.UnitTests\Services\DesktopTestSourceHostTests.cs(107,57): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type. azure-pipelines test\UnitTests\MSTestAdapter.PlatformServices.UnitTests\Services\DesktopTestSourceHostTests.cs(164,57): error CS8625: (NETCORE_ENGINEERING_TELEMETRY=Build) Cannot convert null literal to non-nullable reference type. |
…tead of null Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Fixed in the latest commit. Both |
Amaury Levé (Evangelink)
commented
May 12, 2026
Note The pull request was not created — a fallback review issue was created instead due to protected file changes: #8140 🤖 Test Improver here. Status update: the LoggingManager tests from this PR landed in main via #8124 and #8130. This PR is a duplicate and can be safely closed.
|
Amaury Levé (Evangelink)
commented
May 13, 2026
Copilot resolve the merge conflicts in this pull request |
…anager-tests-26f492a017011427 # Conflicts: # test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Services/DesktopTestSourceHostTests.cs # test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Merge conflicts resolved in commit |
Uh oh!
There was an error while loading. Please reload this page.
Tests cover:
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com