Search code examples
nunitgithub-actions

Upload NUnit Result File to GitHub Actions


I'm in the process of setting up GitHub Actions for my C# project, and as part of that I want to have the test results displayed in GitHub.

Using this action, the relevant portion of my YML looks like this:

    steps:
      - name: 🎉 Test
        run: dotnet test --no-restore --verbosity normal --logger:"nunit"
      - name: ⏫ Publish Unit Test Results
        uses: EnricoMi/publish-unit-test-result-action@v1
        if: always()
        with:
          files: ${{ github.workspace }}/*/TestResults/*.xml

The tests run correctly, the TestResults.xml is present and gets uploaded, but GitHub Actions prints:

Error processing result file

Invalid format.

Now the documentations are a bit sparse at this point, but from what I could gather both GitHub Actions and NUnit should use the JUnit test result format, and the file looks a lot like this, too:

<test-run id="2" duration="0.028704999999999998" testcasecount="18" total="18" passed="18" failed="0" inconclusive="0" skipped="0" result="Passed" start-time="2022-02-19T 11:32:34Z" end-time="2022-02-19T 11:32:36Z">
  <test-suite type="Assembly" name="HelloCSharp.Api.Tests.dll" fullname="/home/runner/work/hello-c-sharp/hello-c-sharp/HelloCSharp.Api.Tests/bin/Debug/net6.0/HelloCSharp.Api.Tests.dll" total="18" passed="18" failed="0" inconclusive="0" skipped="0" result="Passed" start-time="2022-02-19T 11:32:36Z" end-time="2022-02-19T 11:32:36Z" duration="0.028705">
    <test-case name="DisplayNameForAll" fullname="HelloCSharp.Api.Tests.Models.RelationshipTypeTest.DisplayNameForAll" methodname="DisplayNameForAll" classname="RelationshipTypeTest" result="Passed" start-time="2022-02-19T 11:32:36Z" end-time="2022-02-19T 11:32:36Z" duration="0.006137" asserts="0" seed="1714534364" />
    <!-- snip -->
    <errors />
  </test-suite>
</test-run>

So what could be the problem here?


Solution

  • Okay, NUnit format is definitively not JUnit format. I tried uploading a fix JUnit file and it worked, then I compared the XMLs. JUnit files have "testsuite" and "testcase" tags instead of "test-suite" and "test-case".

    So my quick and dirty solution is too add this step between the ones in the question:

          - name: ☢ Reformat Test Files (NUnit != JUnit)
            run: |
              sed -i 's/test-case/testcase/' ${{ github.workspace }}/*/TestResults/*.xml
              sed -i 's/test-suite/testsuite/' ${{ github.workspace }}/*/TestResults/*.xml
              sed -i 's/test-run/testsuite/' ${{ github.workspace }}/*/TestResults/*.xml