Uh oh!
There was an error while loading. Please reload this page.
[Test Improver] Add unit tests for LoggingManager.BuildAsync - #8130
Conversation
Tests cover: - AddProvider(null) throws ArgumentNullException - Non-extension provider is always included - IExtension provider with IsEnabledAsync()=true is included - IExtension provider with IsEnabledAsync()=false is excluded (not added to factory) - IAsyncInitializableExtension provider has InitializeAsync() called - Disabled extension provider does NOT have InitializeAsync() called - Factory is invoked with the correct LogLevel and IServiceProvider Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a focused unit-test suite for LoggingManager.BuildAsync (Microsoft.Testing.Platform logging pipeline) to validate provider registration, extension enablement filtering, async initialization behavior, and factory delegate inputs.
Changes:
- Added unit tests validating
AddProvider(null)throws and that providers are included/excluded based onIExtension.IsEnabledAsync(). - Added unit tests validating
IAsyncInitializableExtension.InitializeAsync()is invoked only for included providers. - Added a unit test validating the provider factory receives the expected
LogLevelandIServiceProvider.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs | New unit tests covering LoggingManager.BuildAsync provider filtering, initialization, and factory argument passing. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
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
The new LoggingManagerTests are well-structured and cover the core scenarios cleanly. Three minor improvements stand out:
Missing test (Important) — The enabled
IExtension+IAsyncInitializableExtensioncombination isn't tested. The disabled path is covered, but the enabled path (which should callInitializeAsync()) has no corresponding test.Incomplete assertion (Minor) —
BuildAsync_WithInitializableProvider_CallsInitializeAsyncverifiesInitializeAsync()was invoked but doesn't verify the provider was included in the resulting factory. The other "include" tests check both; this one should too.Ambiguous test name (Minor) —
BuildAsync_WithInitializableProvider_CallsInitializeAsyncdoesn't communicate that the provider intentionally omitsIExtension. This distinction is meaningful given the two code paths under test.
Positive Highlights
- Consistent test structure and naming convention across all methods.
- Good use of interface composition to isolate specific behavioural combinations (extension-only, initializable-only, both).
- Internal test interfaces correctly follow the semicolon shorthand style (consistent with
IDisposableLoggerProviderinLoggerFactoryTests.cs). _mockMonitorsetup in the constructor mirrors the pattern inLoggerFactoryTests.
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.
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
Analysis
This PR adds a single new test file (LoggingManagerTests.cs) with 7 test methods covering LoggingManager.BuildAsync. I reviewed the tests against the production implementation in LoggingManager.cs and LoggerFactory.cs.
Verified Correctness
- Null guard test: Correctly verifies that
AddProvider(null!)throwsArgumentNullException— matches the production?? throw new ArgumentNullException(...)guard. - Provider inclusion/exclusion: Tests for enabled/disabled
IExtensionproviders correctly map to theif (serviceInstance is IExtension extension && !await extension.IsEnabledAsync())branch in production. - Initialization ordering:
BuildAsync_WithInitializableProvider_CallsInitializeAsynccorrectly verifiesTryInitializeAsynccallsInitializeAsyncwhen the provider implementsIAsyncInitializableExtension. The separateBuildAsync_WithDisabledExtensionProvider_DoesNotCallInitializeAsynccorrectly confirms thecontinuestatement prevents initialization of disabled extensions. - Factory parameter forwarding: The capture-variable approach in
BuildAsync_PassesLogLevelAndServiceProviderToFactorycorrectly exercises thefactory(logLevel, serviceProvider)call site. IMonitormock setup: The_mockMonitor.Setup(m => m.Lock(...)).Returns(...)correctly satisfiesLoggerFactory.CreateLogger'susing (_monitor.Lock(_sync))pattern.
Threading & Concurrency
Each MSTest test method gets a fresh LoggingManagerTests instance, so the readonly Mock<> fields are not shared between tests. No threading concerns.
API Compliance
All assertions use MSTest APIs (Assert.ThrowsExactly, Assert.AreEqual, Assert.AreSame) and Moq Verify() — compliant with the project's BannedSymbols.txt which bans AwesomeAssertions.
Key Findings
No issues found in any review category (correctness, threading, performance, API compat, cross-TFM, resources, security, defensive coding).
Generated by Expert Code Reviewer
🧠 Reviewed by Expert Code Reviewer 🧠
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
- [Coverage] Missing test: enabled extension + initializable provider — The production code has a path where a provider implements both
IExtension(enabled) andIAsyncInitializableExtension, causingInitializeAsync()to be called after theIsEnabledAsync()=truecheck. This path is not exercised.BuildAsync_WithInitializableProvider_CallsInitializeAsync(line 76) does not cover it becauseIInitializableLoggerProviderdoesn't implementIExtension, so theis IExtensioncheck is false and it takes a completely different branch.IExtensionAndInitializableLoggerProvider(line 131) exists but is only used in the disabled case.
What's Good
- Isolation: Each test constructs a fresh
LoggingManager; instance-level mocks are recreated per-test by MSTest's per-method instantiation — no shared mutable state. - Assertions: Moq
VerifywithTimes.Once/Times.Nevergives precise failure messages. - Factory capture pattern in
BuildAsync_PassesLogLevelAndServiceProviderToFactoryis clean and correctly verifies the parameters forwarded to the factory lambda. - Test interfaces declared at the bottom of the file are a neat way to compose the exact capability mix each test needs without boilerplate classes.
Recommendations
Add one test for the enabled+initializable extension case as described in the inline comment — the IExtensionAndInitializableLoggerProvider interface is already available at the bottom of the file.
Generated by Test Expert Reviewer
🧪 Test quality reviewed by Test Expert Reviewer 🧪
Uh oh!
There was an error while loading. Please reload this page.
Amaury Levé (Evangelink)
commented
May 11, 2026
Copilot address review comment |
…ing enabled+initializable test Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Amaury Levé (Evangelink)
commented
May 11, 2026
Copilot resolve the merge conflicts in this pull request |
…anager-tests-fa2bb034a593d608 # Conflicts: # test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Uh oh!
There was an error while loading. Please reload this page.
Tests cover:
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>