Process Coverage not working with Sonarqube

Hello Fellow,

I am trying to implement JUnit Coverage for all BPMN processes using SonarQube in Spring boot and JUnit5 but not showing any graphical view of Process coverage Percentage.


org.camunda.bpm.assert
camunda-bpm-assert
15.0.0
test


org.camunda.bpm
camunda-bpm-junit5
7.21.0
test


org.camunda.bpm.extension
camunda-bpm-process-test-coverage-junit5
1.0.0
test


org.junit.jupiter
junit-jupiter
test


org.camunda.bpm.extension
camunda-bpm-process-test-coverage
0.3.2
test


com.h2database
h2


org.camunda.community.process_test_coverage
sonar-camunda-process-test-coverage-plugin
2.4.0

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring.boot.version}</version>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
            <version>2.22.0</version>
        </plugin>
        <plugin>
            <groupId>org.jacoco</groupId>
            <artifactId>jacoco-maven-plugin</artifactId>
            <version>0.8.10</version>
            <executions>
                <execution>
                    <id>prepare-agent</id>
                    <goals>
                        <goal>prepare-agent</goal>
                    </goals>
                </execution>
                <execution>
                    <id>report</id>
                    <goals>
                        <goal>report</goal>
                    </goals>
                    <configuration>
                        <formats>
                            <format>XML</format>
                        </formats>
                        <outputDirectory>target/process-test-coverage</outputDirectory>
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <append>true</append>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.sonarsource.scanner.maven</groupId>
            <artifactId>sonar-maven-plugin</artifactId>
            <version>4.0.0.4121</version>
        </plugin>
    </plugins>
</build>

image

Hi @Veb.

First of you’re mixing old versions of the extension with a new one.
Please use only (remove the dependencies with groupId org.camunda.bpm.extension, as those are not supported anymore)

<dependency>
  <groupId>org.camunda.community.process_test_coverage</groupId>
  <artifactId>camunda-process-test-coverage-junit5-platform-7</artifactId>
  <version>2.6.0</version>
  <scope>test</scope>
</dependency>

And look here for the sonar plugin (it needs to be installed into your sonarqube installation):

Afterwards you need to make sure, that your BPMN process definitions are also included in the sonar analysis (e.g. by including them in the sonar.sources property: -Dsonar.sources=src/main,pom.xml as default is not including the resources directory).

1 Like

Hello @rohwerj
Thank you for response.

But couldn’t able to find plugin and unable get the json report of test coverage calculation suggested in attached screenshot of Sonarqube documentation.

Hi @Veb
The plugin JAR that needs to be installed in Sonarqube can e.g. be found here:
https://repo1.maven.org/maven2/org/camunda/community/process_test_coverage/sonar-camunda-process-test-coverage-plugin/2.6.0/sonar-camunda-process-test-coverage-plugin-2.6.0.jar

When you start Sonarqube, you should afterwards see the following when opening the administration tab.

Afterwards (when the plugin is installed in Sonarqube), I for example run the following command in my project to send the reports:

mvn sonar:sonar -Dsonar.login=xxx -Dsonar.password=xxx -Dsonar.sources=src/main,pom.xml

@rohwerj
Thank you plugin and configuration.

After making changes, could not solve the issue.
In Process Test coverage getting empty screen, also missing the Process Test Coverage option in Coverage tab.
Kindly please have look on attached screenshot. Kindly suggest on this.

Thank You.

As long as your reports are in the default location (target/process-test-coverage) you don’t need to change the setting in the Sonar plugin (just leave the field empty).
Could you please show me the output of the Sonar analysis (when calling mvn sonar:sonar)?
There should be some line like:

"Importing {} report(s). Turn your logs in debug mode in order to see the exhaustive list."

Thank you for suggestions.
This log getting multiple time kindly find the attached sonar log screenshot.

Thank you.

Very strange. As we can see from the log, it’s picking up the reports just fine.
If you navigate to the BPMN files in Sonarqube, you see no coverage measure?

And if you open the DevTools in chrome, do you see any errors in the console when opening the process test coverage page under the “more” option?

I am getting error on click Process Test coverage under “more” option

Also if you see in below screenshot I am also nor getting BPMN files list nor ‘Process Test Coverage’ option under in Measure → Coverage.

I have those same exceptions in the console and it’s still working for me.
If you don’t see the BPMN files under code section, then you have a problem that those are not picked up by the sonar analysis.
Please be sure to again check your sonar.sources property you pass to the maven plugin. It should include the bpmn files for your processes you test.

Hello @rohwerj
now I am facing error for project analysis setup even after Build Success.

mvn clean verify sonar:sonar -Dsonar.login=admin -Dsonar.password=*** -Dsonar.sources=src/main,pom.xml

Please suggest on this.

Hello @Veb
There’s some test that is registered with the extension, but no Camunda events are thrown (maybe not a relevant process test).
Currently that leads to a coverage of NaN and will apparently fail, when imported to Sonarqube.
With the upcoming version 2.7.0 this situation will be fixed and such tests will be ignored.

Even though I didnt changed anything not test classes still this error raised in Sonarqube, As Last Analysis has failed.
Any Solution over this @rohwerj
Thank You

Hi @Veb
Watch the output of the test execution. There should be at least one test class, where you see something like
Test coverage of … is NaN.
Use the annotation @ExcludeFromProcessTestCoverage to exclude this test class from the coverage, as it anyway captures no events from Camunda.
In the next version 2.7.0 this test class will be automatically ignored, but currently you have to explicitely do this.

After build succeed I cant see any such NAN in Test coverage in any Test classes.

Also I ran each individual Test class, but not found any Coverage error.

You would only see that output on the console, not in the HTML report.
We just released version 2.7.0, which handles this situation better.
Could you please test, whether that version solves your problems?

Couldn’t get error ‘NaN is not allowed as a Measure value’ any log.
And not getting solution over this issue in version 2.6.0.

And with the new version 2.7.0?
But you still see the error NaN in the Sonarqube analysis log?

Yes Still getting error NAN… Could not able to configure project in Sonarqube for Analysis.


kindly suggest on project configuration in Sonarqube dashboard.

@rohwerj Could you please suggest on this sonarqube error.
Couldn’t find any log or error in test execution console or in sonar build logs.