Sonarqube does not 'see' a junit test report that is really there (test class naming or @TestFactory annotation issue?)

This is probably a duplicate, but a discourse search for sonar.junit.reportPaths yielded no results for me.

$ ./gradlew :logging-core:sonarqube
...
> Task :logging-core:sonarqube
Resource not found: xx.xxxxx.common.logging.StructuredLoggerSpecs under the directory /xx-logging/core while reading test reports. Please, make sure your "sonar.junit.reportPaths" property is configured properly

> Task :logging-core:sonarqube FAILED

FAILURE: Build failed with an exception.
$ find /xx-logging/core -name "*.xml"
/xx-logging/core/build/test-results/test/TEST-xx.xxxxx.common.logging.LogSplittingTest.xml
/xx-logging/core/build/test-results/test/TEST-xx.xxxxx.common.logging.StructuredLoggerSpecs.xml
...

In the web page for the project where sonarqube failed, I see indeed the LogSplittingTests result has been found, so it’s only the StructuredLoggerSpecs.xml that, despite being present, is not found.

$ cat /xx-logging/core/build/test-results/test/TEST-xx.xxxxx.common.logging.LogSplittingTest.xml<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="xx.xxxxx.common.logging.LogSplittingTest" tests="3" skipped="0" failures="0" errors="0" timestamp="2021-03-31T17:57:50" hostname="xx-xxxxx-xxx" time="0.085">
  <properties/>
  <testcase name="doesNotSplitMessageUnderMaxLength()" classname="xx.xxxxx.common.logging.LogSplittingTest" time="0.027"/>
  <testcase name="doesNotSplitMessageOfExactlyMaxLength()" classname="xx.xxxxx.common.logging.LogSplittingTest" time="0.002"/>
  <testcase name="splitsMessageOverMaxLength()" classname="xx.xxxxx.common.logging.LogSplittingTest" time="0.054"/>
  <system-out><![CDATA[]]></system-out>
  <system-err><![CDATA[]]></system-err>
</testsuite>

$ cat /xx-logging/core/build/test-results/test/TEST-xx.xxxxx.common.logging.StructuredLoggerSpecs.xml
<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="xx.xxxxx.common.logging.StructuredLoggerSpecs" tests="2" skipped="0" failures="0" errors="0" timestamp="2021-03-31T17:57:50" hostname="xx-xxxxx-xxx" time="0.031">
  <properties/>
  <testcase name="1st dynamic test" classname="xx.xxxxx.common.logging.StructuredLoggerSpecs" time="0.022"/>
  <testcase name="2nd dynamic test" classname="xx.xxxxx.common.logging.StructuredLoggerSpecs" time="0.003"/>
  <system-out><![CDATA[]]></system-out>
  <system-err><![CDATA[]]></system-err>
</testsuite>

The StructuredLoggerSpecs class contains a @TestFactory annotation, so it could be that:

class StructuredLoggerSpecs {

    @TestFactory
    fun dynamicTestsFromCollection(): Collection<DynamicTest?>? {

Or it could be that the *Specs name filter is causing trouble in my conventions module:

tasks.withType<Test>  {
    useJUnitPlatform()
    filter {
        includeTestsMatching("*Test")
        includeTestsMatching("*Specs")
    }
}

Versions used:

  • org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.32
  • org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:3.1.1
  • org.junit.platform:junit-platform-engine:1.7.1

Thoughts?

I was having the same issue (and thus found this post). For what it’s worth, I was able to get rid of the errors by making sure the test class name exactly matched the filename of the test. E.g. a file of AwesomeTest.kt that defined class GreatTest {} would throw that warning until I renamed the file to GreatTest.kt.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.