Skip to content

Consolidate push/PR test runs into single dotnet test invocation for one HTML report#3

Merged
srmiljus merged 2 commits into
mainfrom
copilot/consolidate-test-reports
Mar 26, 2026
Merged

Consolidate push/PR test runs into single dotnet test invocation for one HTML report#3
srmiljus merged 2 commits into
mainfrom
copilot/consolidate-test-reports

Conversation

Copilot AI commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

Two separate dotnet test steps on push/PR each triggered [BeforeTestRun], causing ExtentReportHelper to initialize twice and produce two timestamped HTML artifacts instead of one consolidated report.

Workflow (tests.yml)

  • Replaced the two push/PR steps (filtered + intentional-fail) with a single unfiltered dotnet test step with continue-on-error: true — one process, one [BeforeTestRun], one report

ExtentReportHelper

  • Added LogKnownFailure(string) — logs with Warning status and [EXPECTED FAILURE] prefix
  • Added MarkTestAsKnownFailure(string) — logs a ⚠️ [KNOWN / EXPECTED FAILURE] warning on the test node itself, which drives ExtentReports to render the test as orange (Warning) rather than red (Fail)

Hooks

  • Extracted "intentional-fail" to private const string IntentionalFailTag
  • AfterStep: detects @intentional-fail → calls LogWarning instead of LogFail for the failing step
  • AfterScenario: detects @intentional-fail → uses "EXPECTED FAIL" screenshot label and calls MarkTestAsKnownFailure instead of treating the error as a genuine failure
// AfterScenario — intentional-fail treated as Warning, not Fail
bool isKnownFailure = _scenarioContext.ScenarioInfo.Tags.Contains(IntentionalFailTag);
var screenshotLabel = isKnownFailure ? "EXPECTED FAIL" : "FAIL";
// ...
if (isKnownFailure)
    ExtentReportHelper.Instance.MarkTestAsKnownFailure("Deliberately incorrect assertion...");

Net result: one HTML report per CI run; regular tests ✅ green, intentional-fail ⚠️ orange with clear label, pipeline stays green.

Original prompt

Problem

When the workflow runs on push or pull_request, two separate dotnet test steps are executed:

  1. Run tests excluding intentional-fail (push/PR) — runs all tests except @intentional-fail
  2. Run intentional-fail test (push/PR - expected to fail) — runs only @intentional-fail

Because Reqnroll fires [BeforeTestRun] once per process, each dotnet test invocation initializes ExtentReportHelper separately and creates its own timestamped HTML report. This results in two uploaded artifacts — one per test run — which is unprofessional.

Goal

Produce one single consolidated HTML report per CI run where:

  • All regular tests show as ✅ Pass
  • The intentional-fail scenario shows as ⚠️ Warning (Expected Failure) with a clear [EXPECTED FAILURE] label — not as a red Fail
  • The workflow still exits successfully (pipeline is green)

Changes Required

1. .github/workflows/tests.yml

Replace the two separate push/PR test steps with a single dotnet test step that runs all tests together with continue-on-error: true.

The current two steps to replace:

      - name: Run tests excluding intentional-fail (push/PR)
        if: github.event_name != 'workflow_dispatch'
        env:
          BROWSER_HEADLESS: 'true'
        run: |
          dotnet test NotchContactFormTests/NotchContactFormTests/NotchContactFormTests.csproj \
            --no-build \
            --filter "Category!=intentional-fail"

      - name: Run intentional-fail test (push/PR - expected to fail)
        if: github.event_name != 'workflow_dispatch'
        env:
          BROWSER_HEADLESS: 'true'
        run: |
          dotnet test NotchContactFormTests/NotchContactFormTests/NotchContactFormTests.csproj \
            --no-build \
            --filter "Category=intentional-fail"
        continue-on-error: true

Replace with a single step:

      - name: Run all tests (push/PR)
        if: github.event_name != 'workflow_dispatch'
        env:
          BROWSER_HEADLESS: 'true'
        run: |
          dotnet test NotchContactFormTests/NotchContactFormTests/NotchContactFormTests.csproj \
            --no-build
        continue-on-error: true

2. NotchContactFormTests/NotchContactFormTests/Helpers/ExtentReportHelper.cs

Add a LogKnownFailure(string message) method that logs with Warning status:

public void LogKnownFailure(string message)
    => _currentTest?.Warning($"[EXPECTED FAILURE] {message}");

Also add a MarkTestAsKnownFailure(string reason) method that marks the current test node itself as Warning status with a clear label. In ExtentReports, a test's final status is determined by the highest-severity log entry — so logging a Warning (instead of Fail) will make the test show as Warning/orange rather than red Fail.

Add:

public void MarkTestAsKnownFailure(string reason)
{
    _currentTest?.Warning($"⚠️ [KNOWN / EXPECTED FAILURE] This test is intentionally failing to demonstrate failure reporting.\nReason: {reason}");
}

3. NotchContactFormTests/NotchContactFormTests/Hooks/Hooks.cs

In the AfterScenario hook, detect whether the failing scenario has the @intentional-fail tag. If it does, call MarkTestAsKnownFailure instead of LogFail, so the report shows it as Warning (orange) instead of Fail (red).

Current AfterScenario:

[AfterScenario]
public void AfterScenario()
{
    if (_scenarioContext.TestError != null)
    {
        try
        {
            var screenshotHelper = _container.Resolve<ScreenshotHelper>();
            var base64 = screenshotHelper.CaptureScreenshotAsBase64(
                _scenarioContext.ScenarioInfo.Title, "FAIL");

            if (!string.IsNullOrEmpty(base64))
                ExtentReportHelper.Instance.AttachScreenshot(base64, "Screenshot at failure");
        }
        catch { /*screenshot failure must not mask the original error */ }
    }

    _driverContext?.Dispose();
}

Update to:

[AfterScenario]
public void AfterScenario()
{
    if (_scenarioContext.TestError != null)
    {
        bool isKnownFailure = _scenarioContext.ScenarioInfo.Tags.Contains("intentional-fail");

        try
        {
            var screenshotHelper = _container.Resolve<ScreenshotHelper>();
            var screenshotLabel = isKnownFailure ? "EXPECTED FAIL" : "FAIL";
            var base64 = screenshotHelper.CaptureScreenshotAsBase64(
                _scenarioContext.ScenarioInfo.Title, screenshotLabel);

            if (!string.IsNullOrEmpty(base64))
                ExtentReportHelper.Instance.AttachScreenshot(base64, $"Screenshot at {screenshotLabel}");
        }
        catch { /* screenshot failure must not mask the original error */ }

        if (isKnownFailure)
        {
            ExtentReportHelper.Instance.MarkTestAsKnownFailure(
                "Assertion uses a deliberately incorrect expected value to demonstrate failure reporting in ExtentReports.");
        }
    }

...

</details>



<!-- START COPILOT CODING AGENT SUFFIX -->

*This pull request was created from Copilot chat.*
>

<!-- START COPILOT CODING AGENT TIPS -->
---

📍 Connect Copilot coding agent with [Jira](https://gh.io/cca-jira-docs), [Azure Boards](https://gh.io/cca-azure-boards-docs) or [Linear](https://gh.io/cca-linear-docs) to delegate work to Copilot in one click without leaving your project management tool.

- Replace two separate push/PR dotnet test steps with a single step
  (no --filter, with continue-on-error: true) so Reqnroll fires
  [BeforeTestRun] only once and produces one HTML report
- Add LogKnownFailure() and MarkTestAsKnownFailure() to ExtentReportHelper
  to log intentional failures as Warning (orange) instead of Fail (red)
- Update AfterScenario and AfterStep hooks to detect @intentional-fail tag
  and use Warning-based reporting; extract tag string to a constant

Co-authored-by: srmiljus <81557246+srmiljus@users.noreply.github.com>
Agent-Logs-Url: https://github.com/srmiljus/Notch_Automation_Task/sessions/5d972fa1-8498-48f9-ab4b-7a0909c8159f
Copilot AI changed the title [WIP] Consolidate test reports into a single HTML output Consolidate push/PR test runs into single dotnet test invocation for one HTML report Mar 26, 2026
Copilot AI requested a review from srmiljus March 26, 2026 08:26
@srmiljus srmiljus marked this pull request as ready for review March 26, 2026 08:28
@srmiljus srmiljus merged commit 6b0a0ed into main Mar 26, 2026
1 check passed
@srmiljus srmiljus deleted the copilot/consolidate-test-reports branch March 26, 2026 15:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants