Ctest in Bitbucket

I have a repository in C,C++ that is being analyzed in bitbucket with sonarqube cloud. I have coverage working with ctest. However, due to the specific nature of this repository, some unit tests will fail in certain environments. We know the cause for this and are not concerned about the failures; however, when there is a failure, I get no code coverage at all for that analysis. Even if 36/37 unit tests pass, the coverage goes back down to zero. I have previously gotten around this by specifying only running certain unit tests - and that works in a pinch. It’s not a good long-term solution though. Wondering if there is anything I can do in the properties file or my pipeline to get the remaining code coverage even with a failing unit test. Thanks!

Hey there.

From what you’ve described, it sounds like your current pipeline is not generating a coverage report if any unit tests fail. In my experience, build systems typically halt execution when a test fails, which could explain why the coverage report isn’t being produced in those cases.

However, it’s worth noting that SonarQube itself simply reads the coverage report that is provided—it doesn’t care whether the tests themselves pass or fail.

I would recommend checking your pipeline and test execution scripts to confirm that the coverage generation step always executes, even if some tests fail (if that’s what you want). This often involves tweaking the test commands so that failures don’t break the sequence of steps (for example, using commands like ctest --output-on-failure; [coverage command], or ensuring script steps continue after non-zero exit statuses).

You can always check what the scanner sees regarding coverage by following this guide: