[Test Improver] test: add unit tests for LoggingManager.BuildAsync and ExtensionValidationHelper.ValidateUniqueExtension#8131
Conversation
…ationHelper.ValidateUniqueExtension Adds 10 tests for LoggingManager.BuildAsync covering: - No providers case - Non-extension provider inclusion - Extension provider enabled/disabled filtering - IAsyncInitializableExtension initialization - Multiple providers handling - Factory receives correct log level and service provider Adds 16 tests for ExtensionValidationHelper.ValidateUniqueExtension covering: - Null argument validation for both overloads - Empty collection (no-throw) - No-duplicate case (no-throw) - Single and multiple duplicates (throw) - Error message content (uid and type names) - Custom selector overload Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds targeted unit-test coverage in Microsoft.Testing.Platform.UnitTests for two internal helpers in Microsoft.Testing.Platform: log factory construction (LoggingManager.BuildAsync) and extension UID uniqueness enforcement (ExtensionValidationHelper.ValidateUniqueExtension).
Changes:
- Add
LoggingManager.BuildAsynctests covering provider inclusion/exclusion (extension enabled/disabled), async initialization, multiple providers, and argument validation forAddProvider. - Add
ExtensionValidationHelper.ValidateUniqueExtensiontests covering null guards for both overloads, duplicate detection (single/multiple), custom selector behavior, and key error-message content.
Show a summary per file
| File | Description |
|---|---|
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs | New tests validating LoggingManager.BuildAsync provider filtering/initialization and factory callback inputs. |
| test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/ExtensionValidationHelperTests.cs | New tests validating duplicate-UID detection and null-guard behavior for both ValidateUniqueExtension overloads. |
Copilot's findings
- Files reviewed: 2/2 changed files
- Comments generated: 0
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
This is a clean, well-structured PR adding unit tests for LoggingManager.BuildAsync and ExtensionValidationHelper.ValidateUniqueExtension. The test naming follows the MethodName_Condition_ExpectedResult convention consistently, coverage is thorough, and the CreateExtension factory helper is a nice touch. A few small improvements are worth considering:
-
Important —
ValidateUniqueExtension_OneDuplicate_ErrorMessageContainsBothTypeNamesasserts onexistingTypeNameandnewTypeName, but since both mocks areMock<IExtension>, Moq produces the same proxy type for both — the two assertions check the same string. The test doesn't actually validate distinct type names. -
Important —
BuildAsync_ExtensionProviderDisabled_IsExcludeddeclaresmockLoggerand sets upCreateLoggeron the disabled provider, but this setup is never invoked. Compare withBuildAsync_ExtensionDisabled_IsNotInitializedwhich correctly omits the unused mock. -
Minor —
mockEnabled/mockDisablednaming inBuildAsync_MixedEnabledAndDisabledExtensions_OnlyEnabledIncludedbreaks themockProvider*naming convention used throughout the rest of the file. -
Minor — Two null-guard tests in
ExtensionValidationHelperTests.csuseMock<IExtension> newExtension = new()instead of theCreateExtension(...)helper used everywhere else. -
Minor — The three helper
internal interfacedeclarations are placed after the test class closing brace; moving them before the class (or to a separate file) makes them easier to discover.
Recommendations
- Fix the
ErrorMessageContainsBothTypeNamestest to use two concreteIExtensionimplementations with different types, or rename the test to reflect what it actually verifies. - Remove the superfluous
mockLogger+CreateLoggersetup from the disabled-provider test.
Generated by PR Nitpick Reviewer
🔍 Meticulously inspected by PR Nitpick Reviewer 🔍
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 — Important]
ValidateUniqueExtension_OneDuplicate_ErrorMessageContainsBothTypeNames: Bothexisting.Object.GetType()andnewExtension.Object.GetType()resolve to the same Moq-generated proxy type, soexistingTypeName == newTypeName. The twoAssert.Containscalls are asserting the same string, providing false confidence that both distinct type names appear in the error message. -
[Coverage — Important] Missing test for the enabled+initializable provider path:
BuildAsync_ExtensionDisabled_IsNotInitializedcovers the disabled case forIEnabledInitializableLoggerProvider, but there is no test verifying that an enabledIEnabledInitializableLoggerProvidergets initialized. This leaves a gap in the production code pathIsEnabledAsync() == true → TryInitializeAsync(). -
[Assertion — Moderate]
BuildAsync_ExtensionDisabled_IsNotInitialized: VerifyingInitializeAsync()isTimes.Neveris necessary but not sufficient. A verification thatIsEnabledAsync()was actually called would close the loop and prevent bugs where the enabled check is bypassed entirely. -
[Assertion — Minor]
BuildAsync_NoProviders_ReturnsEmptyLoggerFactory: The test name claims behavioral verification ("empty factory") but only assertsIsNotNull. Either rename or strengthen the assertion.
Recommendations
- Use concrete stub types (not mocks) in
ErrorMessageContainsBothTypeNamesto get genuinely distinct type names - Add a
BuildAsync_ExtensionEnabled_IsInitializedtest usingIEnabledInitializableLoggerProviderwithIsEnabledAsync()returningtrue - Add
Verify(p => p.IsEnabledAsync(), Times.Once)alongside the existingTimes.Neverassertion - Rename
BuildAsync_NoProviders_ReturnsEmptyLoggerFactoryto reflect what is actually tested
Generated by Test Expert Reviewer
🧪 Test quality reviewed by Test Expert Reviewer 🧪
Evangelink
left a comment
There was a problem hiding this comment.
Summary
Workflow: Expert Code Reviewer
Date: 2026-05-11
Repository: microsoft/testfx
Key Findings
No correctness, threading, performance, API compatibility, resource management, or security issues found.
Verified correct:
-
Assert.Contains(string, string)overload resolution —Assert.Contains("my-uid", ex.Message)correctly resolves to the string-specific overloadContains(string substring, string value), not the collection overload. Checkingex.Messagecontains the substring is accurate. -
IEnabledLoggerProvider / IInitializableLoggerProvider / IEnabledInitializableLoggerProviderinterface design — The three test-local interfaces precisely model the combinations ofILoggerProvider,IExtension, andIAsyncInitializableExtensionthatLoggingManager.BuildAsyncbranches on. The enabled/disabled/initializable logic is exercised correctly. -
LoggingManager.BuildAsyncenabled-check logic — WhenIsEnabledAsync()returnsfalse, thecontinuecorrectly prevents bothTryInitializeAsyncandloggerProviders.Add; the tests forBuildAsync_ExtensionDisabled_IsNotInitializedandBuildAsync_ExtensionProviderDisabled_IsExcludedverify both effects correctly. -
Non-extension initializable provider —
IInitializableLoggerProvider : ILoggerProvider, IAsyncInitializableExtension(withoutIExtension) correctly bypasses the enabled check and proceeds toTryInitializeAsync, as the testBuildAsync_InitializableProvider_IsInitializedverifies. -
ExtensionValidationHelperselector overload — TheWithCustomSelectortest correctly exercises the generic overload with a tuple collection and a selector lambda. -
MSTest assertion APIs — All assertions use MSTest's
Assertclass in accordance with the project'sBannedSymbols.txt(which bans AwesomeAssertions in this test project). -
Internal access —
LoggingManagerandIMonitorareinternal, butMicrosoft.Testing.Platform.UnitTestshas anInternalsVisibleToentry in the main project, so compilation will succeed.
Recommendations
None — the tests are functionally accurate and cover the key behavioral paths.
Generated by Expert Code Reviewer 🧠
🧠 Reviewed by Expert Code Reviewer 🧠
|
@copilot address review comment |
…onHelper tests Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
|
@copilot resolve the merge conflicts in this pull request |
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Merge conflicts resolved. Main had independently landed similar test files via #8124 and #8128 (add/add conflicts). The merged result takes main's version as the base and incorporates our improvements: interfaces placed before the test class, and |
|
@copilot please fix the followinb build errors: @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. |
… calls for Moq 4.20.72 NRT compatibility Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Fixed in the latest commit. Moq 4.20.72 added nullable reference type annotations, so passing a bare |
|
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 work in this PR has been superseded. The LoggingManager tests landed in main via #8124 and #8130, and the ExtensionValidationHelper tests landed via #8128. This PR is a duplicate and can be safely closed.
|
Adds unit tests for
LoggingManager.BuildAsynccovering:CreateLogger)IsEnabledAsynccall verification)IAsyncInitializableExtensioninitialization for both enabled and disabled extension provider pathsAdds unit tests for
ExtensionValidationHelper.ValidateUniqueExtensioncovering:Also fixes a build error in
DesktopTestSourceHostTests.csintroduced by the Moq upgrade to 4.20.72, which added nullable reference type annotations requiringnullliterals passed toMock<TestSourceHost>constructor args to be cast to(IRunSettings?)null.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com