Skip to content

[Test Improver] Add unit tests for ExtensionValidationHelper.ValidateUniqueExtension #8003

Description

@Evangelink

🤖 This PR was created by Test Improver, an automated AI assistant focused on improving tests for this repository.

Goal and Rationale

ExtensionValidationHelper.ValidateUniqueExtension is a shared guard used across the platform to prevent duplicate extension UIDs from being registered. Despite being called at registration time on core paths, it had zero unit test coverage.

Approach

Added ExtensionValidationHelperTests.cs to Microsoft.Testing.Platform.UnitTests/Helpers/ with 15 test methods:

Group Tests
Null guards (generic overload) WhenExistingExtensionsIsNull, WhenNewExtensionIsNull, WhenExtensionSelectorIsNull
Happy path (generic overload) WhenCollectionIsEmpty, WhenNoDuplicateUid
Duplicate detection (generic overload) WhenDuplicateUidExists_Throws, ErrorMessageContainsUid, ErrorMessageContainsTypeNames, WhenMultipleDuplicates_AllTypesInMessage
Selector variant WithWrapperType_SelectsViaFunc, WithWrapperType_NoDuplicate
Simple overload NullExistingExtensions, NullNewExtension, NoDuplicate_DoesNotThrow, DuplicateUid_Throws

Coverage Impact

Metric Before After
Total tests (net8.0 + net9.0) ~1318 1332
New tests +15 (×2 TFMs = +30)

Test Status

✅ Build succeeded (TreatWarningsAsErrors=true)
✅ All 1332 tests pass (net8.0 + net9.0)
✅ No new warnings or errors

Reproducibility

export PATH="$PATH:.dotnet"
dotnet test test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj -c Debug --filter "ExtensionValidationHelper"

Generated by Daily Test Improver · ● 3M ·


Note

This was originally intended as a pull request, but the git push operation failed.

Workflow Run: View run details and download patch artifact

The patch file is available in the agent artifact in the workflow run linked above.

To create a pull request with the changes:

# Download the artifact from the workflow run
gh run download 25294610612 -n agent -D /tmp/agent-25294610612

# Create a new branch
git checkout -b test-assist/extension-validation-helper-tests-076ac6cd367e54b7

# Apply the patch (--3way handles cross-repo patches where files may already exist)
git am --3way /tmp/agent-25294610612/aw-test-assist-extension-validation-helper-tests.patch

# Push the branch to origin
git push origin test-assist/extension-validation-helper-tests-076ac6cd367e54b7

# Create the pull request
gh pr create --title '[Test Improver] Add unit tests for ExtensionValidationHelper.ValidateUniqueExtension' --base main --head test-assist/extension-validation-helper-tests-076ac6cd367e54b7 --repo microsoft/testfx
Show patch preview (260 of 260 lines)
From d86211cbf9882610b00f90ca08029df8b62ff67a Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Mon, 4 May 2026 00:14:20 +0000
Subject: [PATCH] Add unit tests for
 ExtensionValidationHelper.ValidateUniqueExtension

15 tests covering:
- ArgumentNullException for null existingExtensions, newExtension, extensionSelector
- No throw for empty collection and when no duplicate UIDs exist
- InvalidOperationException when duplicate UID found (generic overload)
- Error message contains the duplicate UID and all involved type names
- Multiple duplicates: all types appear in error message
- Wrapper-type selector (generic overload): selects via Func<T, IExtension>
- Simple IExtension overload: null guards, no-duplicate, and duplicate paths

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 .../Helpers/ExtensionValidationHelperTests.cs | 229 ++++++++++++++++++
 1 file changed, 229 insertions(+)
 create mode 100644 test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/ExtensionValidationHelperTests.cs

diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/ExtensionValidationHelperTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/ExtensionValidationHelperTests.cs
new file mode 100644
index 000000000..2defd5f99
--- /dev/null
+++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Helpers/ExtensionValidationHelperTests.cs
@@ -0,0 +1,229 @@
+// Copyright (c) Microsoft Corporation. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+
+using Microsoft.Testing.Platform.Helpers;
+
+namespace Microsoft.Testing.Platform.UnitTests;
+
+[TestClass]
+public sealed class ExtensionValidationHelperTests
+{
+    // Generic overload: ValidateUniqueExtension<T>(IEnumerable<T>, IExtension, Func<T, IExtension>)
+    [TestMethod]
+    public void ValidateUniqueExtension_WhenExistingExtensionsIsNull_ThrowsA
... (truncated)

Metadata

Metadata

Assignees

Labels

area/agentic-workflowsGitHub agentic workflow definitions under .github/workflows/*.md.type/automationCreated or maintained by an agentic workflow.type/test-gapMissing or insufficient tests.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions