Please provide
- Operating system:
Windows 11, or Linux Ubuntu - SonarLint plugin version: N/A
- Programming language you’re coding in:
C# - Is connected mode used:
- Connected to SonarCloud or SonarQube (and which version): 9.7.0.61563
We are using SonarQube at my company.
We are running dotnet tool sonarscanner
in gitlab CI on a linux server, and have successfully uploaded code and coverage data for a project. All is good there.
However, trouble starts when I try to upload test execution information.
I have chosen to only call dotnet build
between sonarscanner begin
and sonarscanner end
steps, since we have already built and tested all the code (with coverage) in separate previous build steps in gitlab, and we have all the test and coverage result artifacts at hand to upload to sonar.
We have a single git repo containing both a C# backend and react.js frontend. We have code and tests from both, and we use cypress as well. So we have 3 sets of tests with coverage. (C# tests using xunit, Javascript tests using Jest, and Cypress tests).
Basically, this is what we are doing in the gitlab job:
- dotnet sonarscanner begin /k:"$SONAR_PROJECT" /d:sonar.login="$SONAR_TOKEN" /d:sonar.host.url="$SONAR_HOST_URL"
/d:sonar.sources="src"
/d:sonar.exclusions="$SONAR_CODE_EXCLUSIONS"
/d:sonar.tests="src"
/d:sonar.test.inclusions="$SONAR_TEST_INCLUSIONS"
/d:sonar.cs.vstest.reportsPaths="${CI_PROJECT_DIR}/src/TestResults/csharp/*.trx"
/d:sonar.sonar.testExecutionReportPaths="${CI_PROJECT_DIR}/src/TestResults/react/sonar-generic.xml,${CI_PROJECT_DIR}/src/TestResults/cypress/sonar-generic.xml"
/d:sonar.coverage.exclusions="$SONAR_COVERAGE_EXCLUSIONS"
/d:sonar.coverageReportPaths="${CI_PROJECT_DIR}/src/TestResults/SonarQube.xml"
/d:sonar.verbose=false
- dotnet build --configuration:$BUILD_CONFIGURATION src/$SOLUTIONNAME
- dotnet sonarscanner end /d:sonar.login="$SONAR_TOKEN"
- We have no issues with reporting coverage information.
- Our c# test execution reports (*.trx) are uploaded just fine.
- My trouble is getting sonar to recognize and accept the test execution files I have given to sonar.sonar.testExecutionReportPaths
for both Jest tests and Cypress tests.
When running both Jest and Cypress tests we are converting the test results into the sonar generic test execution format. i.e.
<testExecutions version="1">
<file path="/builds/rocket/boost/src/WebsiteHost/ClientApp/src/components/Inputs/RadioGroup/Radio.spec.tsx">
<testCase name="Radio throws when used outside of RadioGroup" duration="251" />
</file>
...
</testExecutions>
And uploading them to sonar using sonar.sonar.testExecutionReportPaths
variable (as you can see from above).
The code in my sonarqube UI displays files with paths like this: builds/rocket/boost/src/WebsiteHost/ClientApp/src/components/Inputs/RadioGroup/Radio.spec.tsx
Now, my problem is that my build step is completed successfully, but my UI is still not displaying any unit tests. The count is -
Why are my unit tests not showing?
How can I tell if my test execution reports are being rejected or accepted and why?