Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Tests column empty in Gitlab Ci Pipeline

I am new to Gitlab CI so excuses in advanced. I have a .NET Core Api application which has xUnit tests. I wanted to make a pipeline to have two stages:
Build: Where the code compiles and checks if there are any issues.
Test. If they pass, let me know or if they fail, I would like to see which ones failed.

I am able to achieve this. The build has green/red and Test has green or red depending upon if it builds successfully. But, next to Jobs there is a Tests column in the Pipeline of GitLab and that has 0 tests inside it. In the summary of the test it also says the following:

Summary
0 tests
0 failures
0 errors
0% success rate
0.00ms
Even though in the test job it says:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

A total of 1 test files matched the specified pattern.
Results File: /TestResults/TestResults.xml
Passed!  - Failed:     0, Passed:     7, Skipped:     0, Total:     7, Duration: 1 s - Eic.Test.dll (net8.0)
Saving cache for successful job
00:02
Creating cache default-protected...
WARNING: .nuget/packages/: no matching files. Ensure that the artifact path is relative to the working directory
WARNING: ~/.nuget/packages/: no matching files. Ensure that the artifact path is relative to the working directory 
Archive is up to date!                             
Created cache
Uploading artifacts for successful job
00:02
Uploading artifacts...
/TestResults/TestResults.xml: found 1 matching artifact files and directories 
Uploading artifacts as "archive" to coordinator... 201 Created  id=984 responseStatus=201 Created token=64_rAAG6
Uploading artifacts...
/TestResults/TestResults.xml: found 1 matching artifact files and directories 
Uploading artifacts as "junit" to coordinator... 201 Created  id=984 responseStatus=201 Created token=64_rAAG6
Cleaning up project directory and file based variables
00:01
Job succeeded

Below is my gitlab CI File:

default:
  tags:

image: mcr.microsoft.com/dotnet/sdk:8.0

stages:
  - build
  - test

variables:
  DOTNET_CLI_TELEMETRY_OPTOUT: "1" # Disable .NET Core CLI telemetry
  DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "1" # Disable .NET Core first-time experience

cache:
  paths:
    - .nuget/packages/
    - ~/.nuget/packages/

before_script:
  - cd a.Web.Api
  - dotnet restore a.Web.Api.sln

build:
  stage: build
  script:
    - dotnet build a.Web.Api.sln --configuration Release
  artifacts:
    paths:
      - a.Web.Api/bin/
      - a.Repository/bin/
      - a.Service/bin/
      - a.Domain/bin/

test:
  stage: test
  script:
    - dotnet test  a.Test/a.Test.csproj --configuration Release --logger "trx;LogFileName=TestResults.xml;MethodFormat=Class;FailureBodyFormat=Verbose"

  artifacts:
    when: always
    paths:
      - a.Web.Api/a.Test/TestResults/TestResults.xml
    reports:
      junit: a.Web.Api/a.Test/TestResults/TestResults.xml

Screenshots attached as well: enter image description hereenter image description here

The TestResult.xml is as below:

<?xml version="1.0" encoding="utf-8"?>
<TestRun id="8834c9de-0f40-40e1-aae1-9fc3a2127dba" name="@runner-mtnbomvx-project-21-concurrent-0 2024-05-31 06:25:43" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2010">
  <Times creation="2024-05-31T06:25:43.3278143+00:00" queuing="2024-05-31T06:25:43.3278144+00:00" start="2024-05-31T06:25:40.8137425+00:00" finish="2024-05-31T06:25:44.1430738+00:00" />
  <TestSettings name="default" id="908a77f5-d48a-4d8c-b4fc-4fd606248f27">
    <Deployment runDeploymentRoot="_runner-mtnbomvx-project-21-concurrent-0_2024-05-31_06_25_43" />
  </TestSettings>
  <Results>
    <UnitTestResult executionId="7b19ac7b-d920-4254-a36b-d37ca0fc4623" testId="7d940ce7-9fce-daae-8d17-cf3358a138f8" testName="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_Exception" computerName="runner-mtnbomvx-project-21-concurrent-0" duration="00:00:00.0052100" startTime="2024-05-31T06:25:42.5758187+00:00" endTime="2024-05-31T06:25:42.5758188+00:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="7b19ac7b-d920-4254-a36b-d37ca0fc4623" />
    <UnitTestResult executionId="0dcf7c79-3b1f-45ec-99c0-e5295e10c05b" testId="7e2adae6-d76e-d751-1788-08cdcfd14a67" testName="a.Tests.ServiceTests.UserServiceTest.GetUserAsync_Returns_Null_When_User_Not_Found" computerName="runner-mtnbomvx-project-21-concurrent-0" duration="00:00:00.3007573" startTime="2024-05-31T06:25:42.5620253+00:00" endTime="2024-05-31T06:25:42.5621110+00:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="0dcf7c79-3b1f-45ec-99c0-e5295e10c05b" />
    <UnitTestResult executionId="441a6faa-7216-470b-a5f7-ce90c39a3626" testId="2eaa2c9d-e7bc-e88e-8026-f93efcd1691c" testName="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_NotFound" computerName="runner-mtnbomvx-project-21-concurrent-0" duration="00:00:00.0025948" startTime="2024-05-31T06:25:42.5774074+00:00" endTime="2024-05-31T06:25:42.5774075+00:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="441a6faa-7216-470b-a5f7-ce90c39a3626" />
    <UnitTestResult executionId="2860f77d-7690-497e-befc-22d7bdf52fa7" testId="1dc17961-fcda-8a32-a23b-4effaaac631e" testName="a.Tests.RepositoryTests.UserRepositoryTests.GetUserAsync_ReturnsUser_WhenUserExists" computerName="runner-mtnbomvx-project-21-concurrent-0" duration="00:00:01.7628841" startTime="2024-05-31T06:25:44.0070882+00:00" endTime="2024-05-31T06:25:44.0070885+00:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="2860f77d-7690-497e-befc-22d7bdf52fa7" />
    <UnitTestResult executionId="ec2a689b-a414-4834-9c27-e38612638641" testId="652305ef-da4c-8d04-e449-768e507a747c" testName="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_OkResult_With_User" computerName="runner-mtnbomvx-project-21-concurrent-0" duration="00:00:00.3125378" startTime="2024-05-31T06:25:42.5697205+00:00" endTime="2024-05-31T06:25:42.5697206+00:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="ec2a689b-a414-4834-9c27-e38612638641" />
    <UnitTestResult executionId="160ee3f9-31a1-44f6-a427-605c9741a1ee" testId="f57e934f-0622-8605-9ea7-411156c48077" testName="a.Tests.ServiceTests.UserServiceTest.GetUserAsync_Returns_User" computerName="runner-mtnbomvx-project-21-concurrent-0" duration="00:00:00.0078466" startTime="2024-05-31T06:25:42.5756913+00:00" endTime="2024-05-31T06:25:42.5756913+00:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="160ee3f9-31a1-44f6-a427-605c9741a1ee" />
    <UnitTestResult executionId="5f9d800e-286f-4a04-9d17-14b11268c465" testId="7dc21e3d-8a6e-f91c-2414-3bec2753f026" testName="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_BadRequest" computerName="runner-mtnbomvx-project-21-concurrent-0" duration="00:00:00.0075273" startTime="2024-05-31T06:25:42.5755770+00:00" endTime="2024-05-31T06:25:42.5755771+00:00" testType="13cdc9d9-ddb5-4fa4-a97d-d965ccfc6d4b" outcome="Passed" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" relativeResultsDirectory="5f9d800e-286f-4a04-9d17-14b11268c465" />
  </Results>
  <TestDefinitions>
    <UnitTest name="a.Tests.ServiceTests.UserServiceTest.GetUserAsync_Returns_Null_When_User_Not_Found" storage="/builds/b/a-v2-api/a.web.api/a.test/bin/release/net8.0/a.test.dll" id="7e2adae6-d76e-d751-1788-08cdcfd14a67">
      <Execution id="0dcf7c79-3b1f-45ec-99c0-e5295e10c05b" />
      <TestMethod codeBase="/builds/b/a-v2-api/a.Web.Api/a.Test/bin/Release/net8.0/a.Test.dll" adapterTypeName="executor://xunit/VsTestRunner2/netcoreapp" className="a.Tests.ServiceTests.UserServiceTest" name="GetUserAsync_Returns_Null_When_User_Not_Found" />
    </UnitTest>
    <UnitTest name="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_NotFound" storage="/builds/b/a-v2-api/a.web.api/a.test/bin/release/net8.0/a.test.dll" id="2eaa2c9d-e7bc-e88e-8026-f93efcd1691c">
      <Execution id="441a6faa-7216-470b-a5f7-ce90c39a3626" />
      <TestMethod codeBase="/builds/b/a-v2-api/a.Web.Api/a.Test/bin/Release/net8.0/a.Test.dll" adapterTypeName="executor://xunit/VsTestRunner2/netcoreapp" className="a.Tests.ControllerTests.UserControllerTests" name="GetUserById_Returns_NotFound" />
    </UnitTest>
    <UnitTest name="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_BadRequest" storage="/builds/b/a-v2-api/a.web.api/a.test/bin/release/net8.0/a.test.dll" id="7dc21e3d-8a6e-f91c-2414-3bec2753f026">
      <Execution id="5f9d800e-286f-4a04-9d17-14b11268c465" />
      <TestMethod codeBase="/builds/b/a-v2-api/a.Web.Api/a.Test/bin/Release/net8.0/a.Test.dll" adapterTypeName="executor://xunit/VsTestRunner2/netcoreapp" className="a.Tests.ControllerTests.UserControllerTests" name="GetUserById_Returns_BadRequest" />
    </UnitTest>
    <UnitTest name="a.Tests.RepositoryTests.UserRepositoryTests.GetUserAsync_ReturnsUser_WhenUserExists" storage="/builds/b/a-v2-api/a.web.api/a.test/bin/release/net8.0/a.test.dll" id="1dc17961-fcda-8a32-a23b-4effaaac631e">
      <Execution id="2860f77d-7690-497e-befc-22d7bdf52fa7" />
      <TestMethod codeBase="/builds/b/a-v2-api/a.Web.Api/a.Test/bin/Release/net8.0/a.Test.dll" adapterTypeName="executor://xunit/VsTestRunner2/netcoreapp" className="a.Tests.RepositoryTests.UserRepositoryTests" name="GetUserAsync_ReturnsUser_WhenUserExists" />
    </UnitTest>
    <UnitTest name="a.Tests.ServiceTests.UserServiceTest.GetUserAsync_Returns_User" storage="/builds/b/a-v2-api/a.web.api/a.test/bin/release/net8.0/a.test.dll" id="f57e934f-0622-8605-9ea7-411156c48077">
      <Execution id="160ee3f9-31a1-44f6-a427-605c9741a1ee" />
      <TestMethod codeBase="/builds/b/a-v2-api/a.Web.Api/a.Test/bin/Release/net8.0/a.Test.dll" adapterTypeName="executor://xunit/VsTestRunner2/netcoreapp" className="a.Tests.ServiceTests.UserServiceTest" name="GetUserAsync_Returns_User" />
    </UnitTest>
    <UnitTest name="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_OkResult_With_User" storage="/builds/b/a-v2-api/a.web.api/a.test/bin/release/net8.0/a.test.dll" id="652305ef-da4c-8d04-e449-768e507a747c">
      <Execution id="ec2a689b-a414-4834-9c27-e38612638641" />
      <TestMethod codeBase="/builds/b/a-v2-api/a.Web.Api/a.Test/bin/Release/net8.0/a.Test.dll" adapterTypeName="executor://xunit/VsTestRunner2/netcoreapp" className="a.Tests.ControllerTests.UserControllerTests" name="GetUserById_Returns_OkResult_With_User" />
    </UnitTest>
    <UnitTest name="a.Tests.ControllerTests.UserControllerTests.GetUserById_Returns_Exception" storage="/builds/b/a-v2-api/a.web.api/a.test/bin/release/net8.0/a.test.dll" id="7d940ce7-9fce-daae-8d17-cf3358a138f8">
      <Execution id="7b19ac7b-d920-4254-a36b-d37ca0fc4623" />
      <TestMethod codeBase="/builds/b/a-v2-api/a.Web.Api/a.Test/bin/Release/net8.0/a.Test.dll" adapterTypeName="executor://xunit/VsTestRunner2/netcoreapp" className="a.Tests.ControllerTests.UserControllerTests" name="GetUserById_Returns_Exception" />
    </UnitTest>
  </TestDefinitions>
  <TestEntries>
    <TestEntry testId="7d940ce7-9fce-daae-8d17-cf3358a138f8" executionId="7b19ac7b-d920-4254-a36b-d37ca0fc4623" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
    <TestEntry testId="7e2adae6-d76e-d751-1788-08cdcfd14a67" executionId="0dcf7c79-3b1f-45ec-99c0-e5295e10c05b" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
    <TestEntry testId="2eaa2c9d-e7bc-e88e-8026-f93efcd1691c" executionId="441a6faa-7216-470b-a5f7-ce90c39a3626" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
    <TestEntry testId="1dc17961-fcda-8a32-a23b-4effaaac631e" executionId="2860f77d-7690-497e-befc-22d7bdf52fa7" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
    <TestEntry testId="652305ef-da4c-8d04-e449-768e507a747c" executionId="ec2a689b-a414-4834-9c27-e38612638641" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
    <TestEntry testId="f57e934f-0622-8605-9ea7-411156c48077" executionId="160ee3f9-31a1-44f6-a427-605c9741a1ee" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
    <TestEntry testId="7dc21e3d-8a6e-f91c-2414-3bec2753f026" executionId="5f9d800e-286f-4a04-9d17-14b11268c465" testListId="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
  </TestEntries>
  <TestLists>
    <TestList name="Results Not in a List" id="8c84fa94-04c1-424b-9868-57a2d4851a1d" />
    <TestList name="All Loaded Results" id="19431567-8539-422a-85d7-44ee4e166bda" />
  </TestLists>
  <ResultSummary outcome="Completed">
    <Counters total="7" executed="7" passed="7" failed="0" error="0" timeout="0" aborted="0" inconclusive="0" passedButRunAborted="0" notRunnable="0" notExecuted="0" disconnected="0" warning="0" completed="0" inProgress="0" pending="0" />
    <Output>
      <StdOut>[xUnit.net 00:00:00.00] xUnit.net VSTest Adapter v2.8.0+6438bb880a (64-bit .NET 8.0.6)
[xUnit.net 00:00:00.22]   Discovering: a.Test
[xUnit.net 00:00:00.31]   Discovered:  a.Test
[xUnit.net 00:00:00.32]   Starting:    a.Test
[xUnit.net 00:00:02.19]   Finished:    a.Test
</StdOut>
    </Output>
  </ResultSummary>
</TestRun>

What am I doing wrong?

I tried reading the documentation of Gitlab and the ci file is in line with what they mention should work.

Edit:
For anyone having the same issue, adding JUnitTestLogger from nugget package and then adding the configuration –logger junit in ci file fixed the issue for me

>Solution :

Install package JUnitTestLogger and modify CI file as below.

...
test:
  stage: test
  script:
    - dotnet test  a.Test/a.Test.csproj --configuration Release --logger "junit;LogFileName=TestResults.xml;MethodFormat=Class;FailureBodyFormat=Verbose"

  artifacts:
    when: always
    paths:
      - ./**/TestResults.xml
    reports:
      junit:
        - ./**/TestResults.xml
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading