Error "file is not configured as a test file"

Hello,

At the moment, I’m trying to upload a .xml report of a unit test, using sonar.“testExecutionReportPaths”. The .xml is a modified xml created during bazel test, to have the same format as the one supported.

The xml looks like:

<testExecutions version="1">
  <file path="/home/project/test/files/test.c">
    <testCase name="generic_test" duration="0">
      <skipped message="SUCCESS">other</skipped>
    </testCase>
  </file>
</testExecutions>

And my sonar scanner properties are:

-Dsonar.projectKey=our_project
-Dsonar.projectBaseDir=/home/
-Dsonar.sources=/home/project/
-Dsonar.inclusions=**/*.h,**/*.c,**/*.cpp,**/*.hpp
-Dsonar.cfamily.build-wrapper-output=/home/build_wrapper/ 
-Dsonar.scm.provider=git -Dsonar.sourceEncoding=UTF-8 
-Dsonar.cfamily.threads=16
-Dsonar.host.url=|sonarqube_url|
-Dsonar.login=|sonarqube_token| 
-Dsonar.verbose=true 
-Dsonar.scm.exclusions.disabled=true 
-Dsonar.cfamily.cache.enabled=false 
-Dsonar.externalIssuesReportPaths=/home/report.json 
-Dsonar.testExecutionReportPaths=/home/project/test.xml 
-Dsonar.tests=/home/project/ 
-Dsonar.test.inclusions=/home/project/test/files/test.c 
-X

But it keeps giving me the error: “Caused by: java.lang.IllegalStateException: Line 2 of report refers to a file which is not configured as a test file:…”
I can’t realize why, as I follow the settings that are in the documentation.

As anyone found a similiar issue and, I hope, solution?

Thank you.

Regards

Just a quick update that I forgot to mention, if I make a small change to the scanner properties:

-Dsonar.projectKey=our_project
-Dsonar.projectBaseDir=/home/
-Dsonar.sources=/home/project/
-Dsonar.inclusions=**/*.h,**/*.c,**/*.cpp,**/*.hpp
-Dsonar.cfamily.build-wrapper-output=/home/build_wrapper/ 
-Dsonar.scm.provider=git -Dsonar.sourceEncoding=UTF-8 
-Dsonar.cfamily.threads=16
-Dsonar.host.url=|sonarqube_url|
-Dsonar.login=|sonarqube_token| 
-Dsonar.verbose=true 
-Dsonar.scm.exclusions.disabled=true 
-Dsonar.cfamily.cache.enabled=false 
-Dsonar.externalIssuesReportPaths=/home/report.json 
-Dsonar.testExecutionReportPaths=/home/project/test.xml 
-Dsonar.tests=/home/project/test/files/test.c 
-X

I just removed the sonar.test.inclusions and added the path of the test file directly in the sonar.tests. The error is different, it’s “can’t be indexed twice. Please check that inclusion/exclusion patterns produce disjoint sets for main and test files”.
I did try to

sonar.exclusions=/home/project/test/files/test.c

But it gives the same error.

hello, @AlexSoares,

sonar.sources and sonar.tests are pointing to the same directory. did you try to isolate them?
for example:

  • -Dsonar.sources=/home/project/src
  • -Dsonar.rests=/home/project/test

thanks,

Hello,

Yes, I even tried to run like this:

-Dsonar.projectKey=our_project
-Dsonar.projectBaseDir=/home/
-Dsonar.sources=/home/project/
-Dsonar.inclusions=**/*.h,**/*.c,**/*.cpp,**/*.hpp
-Dsonar.cfamily.build-wrapper-output=/home/build_wrapper/ 
-Dsonar.scm.provider=git -Dsonar.sourceEncoding=UTF-8 
-Dsonar.cfamily.threads=16
-Dsonar.host.url=|sonarqube_url|
-Dsonar.login=|sonarqube_token| 
-Dsonar.verbose=true 
-Dsonar.scm.exclusions.disabled=true 
-Dsonar.cfamily.cache.enabled=false 
-Dsonar.externalIssuesReportPaths=/home/report.json 
-Dsonar.testExecutionReportPaths=/home/project/test.xml 
-Dsonar.tests=/home/project/test/files/test.c 
-Dsonar.test.inclusions=/home/project/test/files/test.c
-Dsonar.exclusions=/home/project/test/files/test.c
-X

Which means I added these parameters regarding the test file:

-Dsonar.tests=/home/project/test/files/test.c 
-Dsonar.test.inclusions=/home/project/test/files/test.c
-Dsonar.exclusions=/home/project/test/files/test.c

But it still gives me “Line 2 of report refers to a file which is not configured as a test file:”

I can’t, however, isolate as you saied. Because my “sonar.sources” is the entire project and there’s several subprojects with tests folders. That’s the reason I have the “sonar.sources” to the project and the “sonar.tests” to the test that I want to upload a report.

Thank you

@AlexSoares,

you can specify multiple comma-separated dirs with sources and tests.

Also, you can keep it simple with something like that

# Define same root directory for main sources and tests
sonar.sources=/home/project/
sonar.tests=/home/project/
# Only take into account files in a test directory for test files
sonar.test.inclusions=/home/project/**/test/**/*
# Exclude files in a test directory from the main source files
sonar.exclusions=/home/project/**/test/**/*

Anyway, I think the root cause is that you are specifying the absolute path of the source and test inclusions/exclusions while they should be relative to the BaseDir. please make them relative and let me know if you still face the issue.
for example:
-Dsonar.test.inclusions=/home/project/test/files/test.c
should be
-Dsonar.test.inclusions=/project/test/files/test.c

Thanks,

@Abbas_Sabra , thank you, it was that exactly. I was following this documentation and it didn’t metion the relative paths. But it worked.

However, I do have on question, if I can use this topic. Regarding the generic xml format, is file path mandatory or can be a way to ignore it? Since we are running bazel test for our unit tests, our test rule can have more than one src file, therefor, more than one file path.

Thnak you

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