This is a .NET library that adapts unit test output into the JUnit result format - with error message and stack trace combined into a single value for compatibility with GitHub/GitLab test pipelines
- The origin JUnitTestLogger creates nice JUnit xml data as required by the specification
- BUT: GitHub respectively the publishing component for unit test results EnricoMi/publish-unit-test-result-action@v1 display either the error message or the stacktrace, but not both
- THAT'S WHY there is the need for a component combining error message and stack trace into a single field
Please note: test project usually requires the nuget package JUnitTestLogger to be able to provide JUnit compatible test results XML file (required
for pushing back details on succeeded/failed tests)
NuGet install command: Install-Package JUnitTestLogger
PLEASE NOTE: a simple dotnet test --results-directory test-results --logger junit might run tests for multiple target frameworks (e.g. net8.0,net48). In effect, the TestResults.xml file would be overwritten by the other framework test results. That's why you should run the unit tests separately for each target Framework.
In your YAML file at .github/workflows/BuildAndTest.yml, define jobs like in following example. Please note the multi-platform/multi-target approach of the example.
build-and-test:
runs-on: ${{ matrix.os }}strategy:
fail-fast: falsematrix:
#arch: [x86, x86_64, arm]os: [windows-latest, ubuntu-latest, macos-latest]include: - os: macos-latestrunNetExe: monosteps:
- name: Checkoutuses: actions/checkout@v4
- name: Setup .NET Coreuses: actions/setup-dotnet@v4with:
dotnet-version: 8.0.x
- name: Install dependenciesrun: dotnet restore
- name: Buildrun: dotnet build --no-restore
- name: Run Unit Testsrun: dotnet test --framework net8.0 --results-directory test-results-net8.0 --logger junit --no-restore
- name: Run Unit Testsrun: dotnet test --framework net48 --results-directory test-results-net48 --logger junit --no-restore
- name: Unit Test Results (Linux) - NET 8.0uses: EnricoMi/publish-unit-test-result-action@v2if: always() && startsWith(matrix.os, 'ubuntu')with:
github_token: ${{ secrets.GITHUB_TOKEN }}files: "test-results-net8.0/TestResults.xml"check_run_annotations: all testscomment_title: Unit Test Statistics (${{matrix.os}}-net8.0)check_name: Unit Test Results (${{matrix.os}}-net8.0)report_individual_runs: true
- name: Unit Test Results (Win/Mac) - NET 8.0uses: EnricoMi/publish-unit-test-result-action/composite@v2if: always() && (!(startsWith(matrix.os, 'ubuntu'))) with:
github_token: ${{ secrets.GITHUB_TOKEN }}files: "test-results-net8.0/TestResults.xml"check_run_annotations: all testscomment_title: Unit Test Statistics (${{matrix.os}}-net8.0)check_name: Unit Test Results (${{matrix.os}}-net8.0)report_individual_runs: true
- name: Unit Test Results (Linux) - NET Framework 4.8uses: EnricoMi/publish-unit-test-result-action@v2if: always() && startsWith(matrix.os, 'ubuntu')with:
github_token: ${{ secrets.GITHUB_TOKEN }}files: "test-results-net48/TestResults.xml"check_run_annotations: all testscomment_title: Unit Test Statistics (${{matrix.os}}-net48)check_name: Unit Test Results (${{matrix.os}}-net48) report_individual_runs: true
- name: Unit Test Results (Win/Mac) - NET Framework 4.8uses: EnricoMi/publish-unit-test-result-action/composite@v2if: always() && (!(startsWith(matrix.os, 'ubuntu'))) with:
github_token: ${{ secrets.GITHUB_TOKEN }}files: "test-results-net48/TestResults.xml"check_run_annotations: all testscomment_title: Unit Test Statistics (${{matrix.os}}-net48)check_name: Unit Test Results (${{matrix.os}}-net48)report_individual_runs: true
- name: Publish Unit Test Results - NET 8.0uses: actions/upload-artifact@v4if: always()with:
name: NUnit Test Results ${{ matrix.os }}path: test-results-net8.0/TestResults.xml
- name: Publish Unit Test Results - NET Framework 4.8uses: actions/upload-artifact@v4if: always()with:
name: NUnit Test Results ${{ matrix.os }}path: test-results-net48/TestResults.xmlIn your YAML file, define a test job like
test_job:
stage: testneeds:
- buildscript:
- 'dotnet test --no-restore --logger "junit;LogFilePath=TestResult.JUnit.xml"'artifacts:
when: always # save test results even when the task failsexpire_in: 1 month paths:
- './TestResult.JUnit.xml'# saving NUnit results as Jenkins JUnit XMLreports:
junit:
- './TestResult.JUnit.xml'# saving NUnit results as Jenkins JUnit XMLhttps://www.nuget.org/packages/JUnitTestLogger4GitHub/
This software is made available by GMV Syncromatics Engineering and CompuMaster GmbH under the MIT license.

