quality gate on pitest mutations is not triggerd when project does not run pitest

162 Views Asked by At

we are using pitest plugin in sonarqube and set up a quality gate on mutation coverage, since it is much more valuable than other coverage measurements. Only, when a project is pushed that does not use pitest, the quality gate is not triggerd at all. Is it possible to define a quality gate to detect that pitest is not defined for a project at all? Thank you

1

There are 1 best solutions below

0
On

Simple answer to your question: no, it's not. Quality gate conditions can not be triggered by the absence of a metric. So a metric has to be computed. But the most recent version of sonar-pitest-plugin (0.9) does only compute coverage information when Mutation Analysis data is present (= a pitest report exists).

The change however is not overly complicated, if you need an urgent fix, check the PitestComputer class at line 84 and add the following else block:

if (mutationsTotal != null) {
  ...
} else {
   context.addMeasure(PitestMetrics.MUTATIONS_KILLED_PERCENT_KEY, 0.0);
}

Compile it and install it manually to your instance.

That said, I want to give you a short heads up, that there is a newer plugin addressing Mutation Analysis in SonarQube (full disclosure: I'm the author), with several new features, rules etc.

The plugin is available via the market place (named "Mutation Analysis"). The plugin has the same limitation as the sonar-pitest-plugin, but I just created a new issue addressing your problem:

https://github.com/devcon5io/mutation-analysis-plugin/issues/13

Edit: This feature is implemented in version 1.3