There’s a “code file” icon on your test file, rather than a “test file” icon. This indicates that the configuration passed into analysis identified this file and/or parent directory as source rather than test. Sort this out and you’ll have it solved.
The sonar.scanner.dumpToFile=[path to file] parameter may be of help here. Per the docs, it
Outputs to the specified file the full list of properties passed to the scanner API as a means to debug analysis.
I always pass project base directory as parameter value of sonar.source, written as sonar.source=. (Maybe this is a bad practice, but it works well until I encountered this problem mentioned here.)
In my case, it seems that:
if the class file under src/test/java folder ends with Test, it will be treated as “Test Code”,
otherwise, recognized as “Source Code”. such as the one mentioned in red rectangle picture.
later on, I try to verify this guess.
So, maybe it’s better to leave it alone. Let it read from build system for Maven?
If you’re building with Maven but manually specifying your basic analysis params, then yes. It’s time to analyze via Maven & let those values be read from the build system: