Generate result report testing with xunit using .NET core
Asked Answered
T

3

8

I have a project ASP.NET core which I integrate unit test with xUnit , Everything work fine but I want to genrate xml report test to integrate in jenkins . Any help please :)

My project.json is :

{
  "version": "1.0.0-*",
  "testRunner": "xunit",
  "dependencies": {
    "xunit": "2.2.0-beta2-build3300",
    "Microsoft.NETCore.App": "1.1.0",
    "dotnet-test-xunit": "2.2.0-preview2-build1029"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
      }
    }
  },
  "runtimes": {
    "ubuntu.16.04-x64": {},
    "win10-x64": {},
    "debian.8-x64": {},
    "win81-x64": {}
  }

}

I'm using the plugin xunit jenkins to display my result test . If their are another way tell me .

Tod answered 17/1, 2017 at 1:43 Comment(2)
Is your xUnit framework is generating xml reports for the tests or not?Fabiola
I don't know how make xUnit generate xml reports this is my question in .NET coreTod
T
2

I find the solution , just add -xml ./path/out.xml . It seems like this :

dotnet test ./WebApi.Tests/ -xml ./WebApi.Tests/out.xml

Tod answered 17/1, 2017 at 10:52 Comment(5)
how did you find this switch? it appears to be undocumented? when you do a dotnet test --help it doesn't give you any "help" about outputting results.Penal
I finded in another issue in github by luck . Yes It's not documented unfortunatelyTod
The support for -xml switch has been dropped in more recent versions of msbuild github.com/dotnet/cli/issues/3114 although you can now output to trx using the --logger:trx switch (as described github.com/dotnet/cli/pull/5181), but I'm now unsure how to get that showing in JenkinsReparative
One way to do it: add " --logger=trx" to the "dotnet test" command and then use the build step "Process xUnit test result report" from the "xUnit plugin". Use the option "MSTest-Version N/A (default) Pattern" and set pattern to "*/.trx".Amar
This is the answer!Stannary
D
7

Old thread but can be useful. In .Net Core 3.1 you can use --logger html to get a read friendly report. dotnet test --logger html

Using:

.Net Core 3.1,
Xunit 2.4.1
Denunciation answered 8/1, 2020 at 7:4 Comment(0)
O
4

I had the same issue in .NET Core 2.0 and dotnet test does not have a -xml switch. So, I relied on a custom logger to do the job:

  1. add NunitXml.TestLogger package to the test project

  2. Run tests using this logger:

    dotnet test "project.csproj" --no-build --verbosity normal --logger:"nunit;LogFilePath=xunit_results.xml"
    

The output is compatible with NUnit results and be used to generate fancy reports like those obtained using ReportUnit.

Osterman answered 3/1, 2019 at 16:51 Comment(1)
The result obtained using that method is null. This returns to me : <test-run id="2" duration="0" testcasecount="0" total="0" passed="0" failed="0" inconclusive="0" skipped="0" result="Passed" start-time="2019-07-24T 23:07:55Z" end-time="2019-07-24T 23:08:15Z"/>Placia
T
2

I find the solution , just add -xml ./path/out.xml . It seems like this :

dotnet test ./WebApi.Tests/ -xml ./WebApi.Tests/out.xml

Tod answered 17/1, 2017 at 10:52 Comment(5)
how did you find this switch? it appears to be undocumented? when you do a dotnet test --help it doesn't give you any "help" about outputting results.Penal
I finded in another issue in github by luck . Yes It's not documented unfortunatelyTod
The support for -xml switch has been dropped in more recent versions of msbuild github.com/dotnet/cli/issues/3114 although you can now output to trx using the --logger:trx switch (as described github.com/dotnet/cli/pull/5181), but I'm now unsure how to get that showing in JenkinsReparative
One way to do it: add " --logger=trx" to the "dotnet test" command and then use the build step "Process xUnit test result report" from the "xUnit plugin". Use the option "MSTest-Version N/A (default) Pattern" and set pattern to "*/.trx".Amar
This is the answer!Stannary

© 2022 - 2024 — McMap. All rights reserved.