Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i use xunit (.net core) test results in jenkins?

I have an asp.net core application that has some tests written in XUnit. How can i use the test results with a tool like jenkins?

like image 544
Ben Yitzhaki Avatar asked Feb 28 '18 09:02

Ben Yitzhaki


People also ask

How do I create a test report in xUnit?

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". This is the answer!


1 Answers

i struggled with this issue so i decided to share my answer based on my experience.

In order to use the test results, we need to output them into XML files that can be used later by a parser. The xml needs to be in the format that the parser knows how to read.

By default, when running dotnet test, it will output the test results into the console. In order to save those results into a file, we should use the "--logger" param. the logger param can accept a logger than will parse the test results into the desired format. in order to parse them into an xunit xml test files that can be used by tools like jenkins, we need to use an external logger named XunitXml.TestLogger. Now we can run the following command:

dotnet test --test-adapter-path:. --logger:xunit

that will export the results into a TestResults folder in each project you have. now we can use these files by any tool, like jenkins to parse those files. jenkins has a plugin named Xunit (how original) that does specifically that. it even lets you set some error thresholds etc.

Update: fegarding jenkins, i have found out that there are plugins that allow you to convert dot TRX results (that dotnet knows to export natively) to XUnit format. that might simplify it and save you that extra dependency. MSTest if one of those - https://wiki.jenkins.io/display/JENKINS/MSTest+Plugin

like image 116
Ben Yitzhaki Avatar answered Sep 22 '22 12:09

Ben Yitzhaki