C/C++ Unit Testing Results Inclusion

I cannot figure out the combination of options, test files, result files, to get my generic test execution results into SonarQube.

  • What language are you writing rules for?

C/C++

  • What have you tried, and what’s your challenge / stumbling block

Importing results in Generic test execution report format

The result file is attached (test_results_PointOfSales_Manage.xml)
test_results_PointOfSales_Manage.xml.txt (994 Bytes)

Here’s the log file from the sonarscan:
sonar_local.log (11.9 KB)

Here’s the pertinent command options:

sonar.cfamily.build-wrapper-output=bw-output
sonar.lauguage=cpp
sonar.sources=CurrentRelease
sonar.exclusions=CurrentRelease/vcast-workarea/**
sonar.test.inclusions=CurrentRelease/test-data/dummy.cpp
sonar.testExecutionReportPaths=xml_data/sonarqube/test_results_post.xml

The errors i’m seeing here here from the log:

INFO: Indexing files...
INFO: Project configuration:
INFO:   Excluded sources: CurrentRelease/vcast-workarea**, sonar.test.inclusions=xml_data/sonarqube/test.cpp
INFO:   Included tests: sonar.test.inclusions=xml_data/sonarqube/test.cpp
...
INFO: Sensor Generic Test Executions Report
INFO: Parsing D:\dev\PointOfSales_v2\xml_data\sonarqube\test_results_PointOfSales_Manage.xml
INFO: Imported test execution data for 0 files
INFO: Test execution data ignored for 1 unknown files, including:
xml_data/sonarqube/test.cpp
INFO: Sensor Generic Test Executions Report (done) | time=10ms

Something really seems messed up if sonar.test.inclusions is showing up under Excluded sources and Included tests

INFO:   Excluded sources: CurrentRelease/vcast-workarea**, sonar.test.inclusions=xml_data/sonarqube/test.cpp
INFO:   Included tests: sonar.test.inclusions=xml_data/sonarqube/test.cpp

Are there any weird characters hidden in your sonar-project.properties file? Can you try passing these values on the command line (sonar-scanner -Dsonar.exclusions=CurrentRelease/vcast-workarea/** -Dsonar.test.inclusions=CurrentRelease/test-data/dummy.cpp, etc...)?

Only thing in the sonar-project.properties is this:

sonar.projectKey=Post_AVT

Here’s the command as is issue it with the key token removed:

sonar-scanner.bat -Dsonar.projectKey=Post_AVT -Dsonar.cfamily.build-wrapper-output=bw-output -Dsonar.host.url=http://localhost:9900 -Dsonar.token=<removed> -Dsonar.lauguage=cpp -Dsonar.sources=CurrentRelease -Dsonar.exclusions=CurrentRelease/vcast-workarea** -Dsonar.test.inclusions=sonar.test.inclusions=xml_data/sonarqube/test.cpp -Dsonar.testExecutionReportPaths=xml_data/sonarqube/test_results_PointOfSales_Manage.xml -Dsonar.cfamily.cobertura.reportPaths=xml_data/cobertura/coverage_results_PointOfSales_Manage.xml

Okay. So a this is an invalid setting.

For a start, it should read:

-Dsonar.test.inclusions=xml_data/sonarqube/test.cpp

Sorry - Early morning and I hadn’t finished my coffee yet.

here’s the current command:

sonar-scanner.bat -Dsonar.projectKey=Post_AVT -Dsonar.cfamily.build-wrapper-output=bw-output -Dsonar.host.url=http://localhost:9900 -Dsonar.token=xxxxxxxxxxxxxxxxxxxxx -Dsonar.lauguage=cpp -Dsonar.sources=CurrentRelease -Dsonar.exclusions=CurrentRelease/vcast-workarea/** -Dsonar.test.inclusions=xml_data/sonarqube/test.cpp -Dsonar.testExecutionReportPaths=xml_data/sonarqube/test_results_PointOfSales_Manage.xml -Dsonar.cfamily.cobertura.reportPaths=xml_data/cobertura/coverage_results_PointOfSales_Manage.xml

Here’s the log from that command
sonar_local.log (12.3 KB)

Well, we’re a little closer.

I would suggest appending -X to the sonar-scanner command, which will print debug logging. From there you’ll be able to see if you have any files being indexed as test at all.

I’ve changed from sonar.testExecutionReportPaths to sonar.cfamily.cppunit.reportsPath and updated our output report formation. I’m getting the data to parse and import.

I don’t know what’s happening with the Generic test execution report format, but I can move on from this to CppUnit.

If I have questions about cppunit test results, I will open a new case

Thanks!

Tim