Skip to content

[Test Improver] Add unit tests for LoggingManager.BuildAsync #7986

@Evangelink

Description

@Evangelink

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

Goal and Rationale

LoggingManager.BuildAsync orchestrates the initialization of all registered ILoggerProvider instances. Its core logic — filtering disabled extensions, calling TryInitializeAsync, and assembling the resulting LoggerFactory — was previously untested.

Tests Added (8 tests × 2 TFMs = 16 total)

Test What it verifies
AddProvider_WithNullFactory_ThrowsArgumentNullException Null guard on AddProvider
BuildAsync_WithNoProviders_ReturnsEmptyLoggerFactory Empty-manager happy path
BuildAsync_PassesLogLevelAndServiceProviderToFactory Factory delegate receives correct LogLevel and IServiceProvider
BuildAsync_WithNonExtensionProvider_IncludesProvider Plain ILoggerProvider is always included
BuildAsync_WithEnabledExtensionProvider_IncludesProvider IExtension.IsEnabledAsync() == true → included
BuildAsync_WithDisabledExtensionProvider_ExcludesProvider IExtension.IsEnabledAsync() == false → excluded
BuildAsync_WithInitializableProvider_CallsInitializeAsync IAsyncInitializableExtension.InitializeAsync() called
BuildAsync_WithDisabledInitializableExtensionProvider_DoesNotCallInitializeAsync Disabled providers skip InitializeAsync

Test Status

✅ All 8 new tests pass (net8.0, 0 warnings)

Reproducibility

export PATH="$PATH:.dotnet"
dotnet test test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj -c Debug -f net8.0 --filter "LoggingManager"

Trade-offs

Low maintenance burden: tests use Moq (already a project dependency) and follow established patterns in the Logging/ test folder.

Generated by Daily Test Improver · ● 1.8M ·


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 25238451326 -n agent -D /tmp/agent-25238451326

# Create a new branch
git checkout -b test-assist/logging-manager-tests-2026-05-02-b508f356a07ba0b9

# Apply the patch (--3way handles cross-repo patches where files may already exist)
git am --3way /tmp/agent-25238451326/aw-test-assist-logging-manager-tests-2026-05-02.patch

# Push the branch to origin
git push origin test-assist/logging-manager-tests-2026-05-02-b508f356a07ba0b9

# Create the pull request
gh pr create --title '[Test Improver] Add unit tests for LoggingManager.BuildAsync' --base main --head test-assist/logging-manager-tests-2026-05-02-b508f356a07ba0b9 --repo microsoft/testfx
Show patch preview (167 of 167 lines)
From eb5b96a1843e0ddf3b4c5b03107233b9456f3e72 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Sat, 2 May 2026 00:16:25 +0000
Subject: [PATCH] Add unit tests for LoggingManager.BuildAsync

Tests cover:
- AddProvider(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>
---
 .../Logging/LoggingManagerTests.cs            | 136 ++++++++++++++++++
 1 file changed, 136 insertions(+)
 create mode 100644 test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs

diff --git a/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs
new file mode 100644
index 0000000..51f1257
--- /dev/null
+++ b/test/UnitTests/Microsoft.Testing.Platform.UnitTests/Logging/LoggingManagerTests.cs
@@ -0,0 +1,136 @@
+// 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.Extensions;
+using Microsoft.Testing.Platform.Helpers;
+using Microsoft.Testing.Platform.Logging;
+
+using Moq;
+
+namespace Microsoft.Testing.Platform.UnitTests;
+
+[TestClass]
+public sealed class LoggingManagerTests
+{
+    private readonly Mock<IMonitor> _mockMonitor = new();
+    private readonly Mock<IServiceProvider> _mockServiceProvider = new();
+
+    public LoggingManagerTests()
+        => _mockMonitor.Setup(x => x.Lock(It.IsAny<object>())).Re
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions