The purpose of the rule is to prohibit the use of JUnit4. However, during the execution of the rule, the obtained full name is “Test” rather than “org.junit.test”, which leads to the failure of the rule’s operation.
However, when executing the rule in a normal environment, the rule runs correctly, which means that the error only occurs during testing.
However, when executing the rule in a normal environment, the rule runs correctly, which means that the error only occurs during testing.
Can you elaborate more on what is a “normal environment”?
I think that in the non-working case, there is some missing semantic information about the annotation package. Maybe you did not compile your test sources before running your unit tests?
Without the compiled files in the classpath, the AST generated will miss semantic information and you will not have the fully qualified name of some classes/methods.
Have you tried upgrading the sonar-java plugin version that you rely on? In the repository you shared I see in the root pom.xml file that the <sonar.java.version> is set to 7.30.0.34429 which is quite old, and I think the issue that you have is related to the classpath being empty in the InternalCheckVerifier that comes from that version, which used a different way of loading the classpath.
Please update to some later sonar-java released version and let me know if the behavior changes
Using the withClassPath(FilesUtils.getClassPath("target/test-jars")) will provide the analysis with the knowledge of all dependencies defined in the pom.xml under:
<!-- only required to run UT - these are UT dependencies -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>test-compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
...
...