Skip to content

Refactor JUnitReport to reuse shared report helper implementations#8950

Merged
Evangelink merged 4 commits into
mainfrom
copilot/duplicate-code-remove-duplicates
Jun 9, 2026
Merged

Refactor JUnitReport to reuse shared report helper implementations#8950
Evangelink merged 4 commits into
mainfrom
copilot/duplicate-code-remove-duplicates

Conversation

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

JUnitReportEngine had local copies of report filename sanitization, target framework moniker resolution, template-based filename resolution, and the retry timeout already defined in SharedExtensionHelpers. This change removes that drift risk by wiring JUnitReport to the same shared implementations already used by sibling report extensions.

  • Align JUnitReport with shared helper usage

    • Link ReportFileNameHelper, ReportFileNameSanitizer, TargetFrameworkMonikerHelper, and ReportFileWriterHelper into Microsoft.Testing.Extensions.JUnitReport.csproj
    • Replace JUnit-local helper implementations with direct calls to the shared helpers
  • Remove duplicate logic from JUnitReportEngine

    • Drop the private copies of:
      • filename sanitization / reserved-name handling
      • TFM resolution
      • template resolution + sanitization
    • Replace the hardcoded retry timeout with ReportFileWriterHelper.FileWriteRetryTimeout
  • Extend parity coverage

    • Add JUnitReport to the existing cross-extension filename sanitization consistency test so Trx/Html/JUnit stay aligned on sanitizer behavior
private string ResolveXmlFileName(string template)
{
    string processName = Path.GetFileNameWithoutExtension(_testApplicationModuleInfo.GetCurrentTestApplicationFullPath());
    string processId = _environment.ProcessId.ToString(CultureInfo.InvariantCulture);
    return ReportFileNameHelper.ResolveAndSanitize(template, processName, processId, _clock.UtcNow);
}

Copilot AI self-assigned this Jun 9, 2026
Copilot AI review requested due to automatic review settings June 9, 2026 05:46
Copilot AI review requested due to automatic review settings June 9, 2026 05:46
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 9, 2026 05:55
Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>
Copilot AI requested review from Copilot and removed request for Copilot June 9, 2026 05:56
Copilot AI changed the title [WIP] Refactor JUnitReportEngine to eliminate duplicate code Refactor JUnitReport to reuse shared report helper implementations Jun 9, 2026
Copilot AI requested a review from Evangelink June 9, 2026 05:57
@Evangelink Evangelink marked this pull request as ready for review June 9, 2026 06:49
Copilot AI review requested due to automatic review settings June 9, 2026 06:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request refactors the Microsoft.Testing.Extensions.JUnitReport extension to reuse the shared report helper implementations already used by other report extensions, reducing duplicated logic and drift risk across extensions.

Changes:

  • Linked shared helpers into Microsoft.Testing.Extensions.JUnitReport.csproj (filename templating/sanitization, TFM moniker resolution, and retry timeout constant).
  • Updated JUnitReportEngine to call the shared helpers instead of maintaining private duplicate implementations.
  • Extended the cross-extension sanitizer parity unit tests to include JUnitReport.
Show a summary per file
File Description
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/ReportFileNameSanitizationConsistencyTests.cs Adds Trx vs JUnit sanitizer parity validation via reflection to keep behavior aligned across extensions.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj Adds a project reference to the JUnitReport extension so the parity test can access JUnitReportEngine.
src/Platform/Microsoft.Testing.Extensions.JUnitReport/Microsoft.Testing.Extensions.JUnitReport.csproj Links shared helper source files from SharedExtensionHelpers into the JUnitReport project.
src/Platform/Microsoft.Testing.Extensions.JUnitReport/JUnitReportEngine.cs Replaces local helper logic with calls to shared helpers and uses the shared retry timeout constant in the error path.

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

@Evangelink

Copy link
Copy Markdown
Member

@copilot resolve the merge conflicts in this pull request

Co-authored-by: Evangelink <11340282+Evangelink@users.noreply.github.com>

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Merge conflicts are resolved in commit 31e0f0f. I reconciled Microsoft.Testing.Extensions.JUnitReport.csproj so it keeps the shared-helper refactor and includes the new validator entry from main.

@Evangelink Evangelink merged commit 1b2b46f into main Jun 9, 2026
5 of 12 checks passed
@Evangelink Evangelink deleted the copilot/duplicate-code-remove-duplicates branch June 9, 2026 08:40
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.

[duplicate-code] Duplicate Code: JUnitReportEngine Duplicates SharedExtensionHelpers (Sanitizer, TFM Helper, ReportFileNameHelper)

3 participants