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:
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
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.