Overview
In this tutorial, we will create a xUnit Test class with multiple Test Cases, implemented in C#.
Description
This simple example is based on a sample xUnit tutorial, which provides some tests using xUnit Fact and Theory concepts.
There are different tests created using the different facilities provided by xUnit, including parameterized tests.
Start by creating a working project and add the necessary dependencies.
dotnet new classlib dotnet add package xunit dotnet add package XunitXml.TestLogger dotnet test --test-adapter-path:. --logger:xunit
Your project should have a configuration similar to the following one.
csharp-xunit-calc.csproj
|
Write your test methods in a class, using Fact and/or Theory.
test/CalcTests.cs
|
You can then run your tests using the xUnit logger which will produce a XML report inside the subfolder "TestResults".
dotnet test --test-adapter-path:. --logger:xunit
After successfully running the Test Case and generating the xUnit XML report (e.g., TestResults.xml), it can be imported to Xray (by using either the REST API or the Import Execution Results action within the Test Execution).
Each xUnit's test is mapped to a Generic Test in Jira, and the Generic Test Definition field contains the namespace, the name of the class, and the method name that implements the Test case.
The Execution Details of the Generic Test contains information about the context, which in this case corresponds to the Test case method, along with the different input values that were validated.