Run code coverage in parallel with static code analysis

This topic is a bit older but I was stumbling across the same request from our developers.

We have a lot of integration tests, that run on another machine and don’t consume much resources on the build instance. This would be a perfect time to do the static code analysis, while waiting for the integration tests to complete and provide the test coverage. Therefor one would have to have smth like a sonarCodeAnalysis and sonarReporting task, while the first only analyzes the code the 2nd would report all the results to the server and perform the QGate resolution.

Would this be possible? Or is there even a way to precompute static code analysis with kind of a dryRun ?

Hello @dgeissl

I split the topic according to the guidelines in our https://community.sonarsource.com/faq

Our static code analysis is done in two steps - most of the code is analyzed during the compilation done by msbuild. And the results are imported during the end step. You can read more about this here.

In theory this could work, as long as the paths inside the code coverage reports are correct.

For example:

  1. on machine 1 - run the begin step, specifying the path where the code coverage reports are expected to be generated
  2. on machine 1 - run the build (static code analysis is done here)
  3. in parallel , on machine 2, run the build w/o code analysis to generate the binaries and run the tests with code coverage enabled and generate ccov reports
  4. on machine 1, wait for the ccov analysis reports to be generated; download them locally in the path mentioned in step 1.
  5. on machine 1, run the end step.

However you need to ensure not to fall in any of the traps mentioned in our code coverage import troubleshooting guide: [Coverage] Troubleshooting guide for .NET code coverage import

1 Like