You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
ReportGeneratorBase<TGenerator, TCapturedTestResult> (src/Platform/SharedExtensionHelpers/ReportGeneratorBase.cs) is a shared base class compiled into every report-generator extension (CTRF, JUnit, HTML, TRX, AzDO). It owns the session-lifecycle orchestration (IsEnabledAsync, ConsumeAsync, OnTestSessionStartingAsync, OnTestSessionFinishingAsync) that every one of those extensions depends on, but had zero direct test coverage — existing tests only exercise the command-line option providers and the report-engine content generation (e.g. CtrfReportEngineTests), never the lifecycle plumbing itself.
Approach
Used CtrfReportGenerator (the thinnest concrete subclass) as the test vehicle. Since its only public constructor takes IServiceProvider, tests construct a real internal Microsoft.Testing.Platform.Services.ServiceProvider, register mocked/fake dependencies for each required service (IFileSystem, IEnvironment, ITestFramework, IConfiguration, ITestApplicationModuleInfo, plus stub implementations of IMessageBus, IClock, ICommandLineOptions, IOutputDevice, ILoggerFactory, ITestApplicationProcessExitCode), and pass it to the constructor — no production code was modified.
New file: test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CtrfReportGeneratorLifecycleTests.cs, covering:
IsEnabledAsync returns true/false based on the --report-ctrf option.
OnTestSessionFinishingAsync throws UnreachableException if called without a prior OnTestSessionStartingAsync (via ApplicationStateGuard.Unreachable()).
Full lifecycle: start → consume passed/failed test node updates (and a non-TestNodeUpdateMessage payload, verifying it's ignored rather than throwing) → finish → assert the SessionFileArtifact is published on the message bus with the correct SessionUid.
No-warning happy path publishes the artifact without writing to the output device.
Coverage impact
Targeted run of the new tests: 5/5 passed. Full Microsoft.Testing.Extensions.UnitTests suite: 1465 passed, 37 skipped, 0 failed (no regressions). Project-level line coverage for microsoft.testing.platform.dll rose slightly (17.9% → the lifecycle paths are now covered) as a side effect of exercising the previously-untested code paths through CtrfReportGenerator.
✅ Build succeeded (0 warnings, 0 errors). ✅ New tests: 5/5 passed. ✅ Full unit test project: 1465 passed / 37 skipped / 0 failed. ✅ dotnet format whitespace --verify-no-changes clean on the new file.
Trade-offs
The ServiceProvider-construction approach is a bit verbose (many mocked dependencies), but it avoids any production code changes and closely mirrors patterns already used in GitHubActionsSlowTestReporterTests.cs. Future report-generator subclasses (JUnit, HTML, TRX) could reuse this same harness pattern if their lifecycle needs coverage too.
Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
southcentralus0.in.applicationinsights.azure.com
To allow these domains, add them to the network.allowed list in your workflow frontmatter:
🤖 Automated content by GitHub Copilot. Generated by the Test Improver workflow. · auto · 496.3 AIC · ⌖ 4.75 AIC · ⊞ 19.5K · [◷]( · ◷) Comment /test-assist to run again
Add this agentic workflow to your repo
To install this agentic workflow, run
gh aw add githubnext/agentics/workflows/test-improver.md@main
Note
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch test-assist/report-generator-base-lifecycle-da53e24e20bcd066.
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (304 of 304 lines)
From e9f47e9514ae2f9176848116105b5fdb788c9f52 Mon Sep 17 00:00:00 2001
X-GH-AW-Base-Commit: a7ea9ab3e15f6946927edb978070ef08b2f7a856
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Fri, 28 Aug 2026 23:09:53 +0000
Subject: [PATCH] Add unit tests for ReportGeneratorBase session lifecycle
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
.../CtrfReportGeneratorLifecycleTests.cs | 282 ++++++++++++++++++
1 file changed, 282 insertions(+)
create mode 100644 test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CtrfReportGeneratorLifecycleTests.cs
diff --git a/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CtrfReportGeneratorLifecycleTests.cs b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CtrfReportGeneratorLifecycleTests.cs
new file mode 100644
index 0000000..8f8e95e
--- /dev/null+++ b/test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CtrfReportGeneratorLifecycleTests.cs@@ -0,0 +1,282 @@+// Copyright (c) Microsoft Corporation. All rights reserved.+// Licensed under the MIT license. See LICENSE file in the project root for full license information.++using System.Diagnostics;+using System.Diagnostics.CodeAnalysis;++using Microsoft.Testing.Extensions.CtrfReport;+using Microsoft.Testing.Platform.CommandLine;+using Microsoft.Testing.Platform.Configurations;+using Microsoft.Testing.Platform.Extensions.Messages;+using Microsoft.Testing.Platform.Extensions.OutputDevice;+using Microsoft.Testing.Platform.Extensions.TestFramework;+using Microsoft.Testing.Platform.Extensions.TestHost;+using Microsoft.Testing.Platform.Helpers;+using Microsoft.Testing.Platform.Logging;+using Microsoft.Testing.Platform.Messages;+using Microsoft.Testing.Platform.OutputDevice;+using Microsoft.Testing.Platform.Services;+using Microsoft.Testing.Platform.TestHost;++using Moq;++namespace Microsoft.Testing.Extensions.UnitTests;++// These tests exercise the shared session lifecycle orchestration in
... (truncated)
Goal
ReportGeneratorBase<TGenerator, TCapturedTestResult>(src/Platform/SharedExtensionHelpers/ReportGeneratorBase.cs) is a shared base class compiled into every report-generator extension (CTRF, JUnit, HTML, TRX, AzDO). It owns the session-lifecycle orchestration (IsEnabledAsync,ConsumeAsync,OnTestSessionStartingAsync,OnTestSessionFinishingAsync) that every one of those extensions depends on, but had zero direct test coverage — existing tests only exercise the command-line option providers and the report-engine content generation (e.g.CtrfReportEngineTests), never the lifecycle plumbing itself.Approach
Used
CtrfReportGenerator(the thinnest concrete subclass) as the test vehicle. Since its only public constructor takesIServiceProvider, tests construct a real internalMicrosoft.Testing.Platform.Services.ServiceProvider, register mocked/fake dependencies for each required service (IFileSystem,IEnvironment,ITestFramework,IConfiguration,ITestApplicationModuleInfo, plus stub implementations ofIMessageBus,IClock,ICommandLineOptions,IOutputDevice,ILoggerFactory,ITestApplicationProcessExitCode), and pass it to the constructor — no production code was modified.New file:
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/CtrfReportGeneratorLifecycleTests.cs, covering:IsEnabledAsyncreturns true/false based on the--report-ctrfoption.OnTestSessionFinishingAsyncthrowsUnreachableExceptionif called without a priorOnTestSessionStartingAsync(viaApplicationStateGuard.Unreachable()).TestNodeUpdateMessagepayload, verifying it's ignored rather than throwing) → finish → assert theSessionFileArtifactis published on the message bus with the correctSessionUid.Coverage impact
Targeted run of the new tests: 5/5 passed. Full
Microsoft.Testing.Extensions.UnitTestssuite: 1465 passed, 37 skipped, 0 failed (no regressions). Project-level line coverage formicrosoft.testing.platform.dllrose slightly (17.9% → the lifecycle paths are now covered) as a side effect of exercising the previously-untested code paths throughCtrfReportGenerator.Reproducibility
Test status
✅ Build succeeded (0 warnings, 0 errors). ✅ New tests: 5/5 passed. ✅ Full unit test project: 1465 passed / 37 skipped / 0 failed. ✅
dotnet format whitespace --verify-no-changesclean on the new file.Trade-offs
The
ServiceProvider-construction approach is a bit verbose (many mocked dependencies), but it avoids any production code changes and closely mirrors patterns already used inGitHubActionsSlowTestReporterTests.cs. Future report-generator subclasses (JUnit, HTML, TRX) could reuse this same harness pattern if their lifecycle needs coverage too.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
southcentralus0.in.applicationinsights.azure.comTo allow these domains, add them to the
network.allowedlist in your workflow frontmatter:See Network Configuration for more information.
Add this agentic workflow to your repo
To install this agentic workflow, run
Note
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch
test-assist/report-generator-base-lifecycle-da53e24e20bcd066.Click here to create the pull request
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (304 of 304 lines)