Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply fb-contrib rules to Unit Tests #18

Closed
ganncamp opened this issue Apr 4, 2016 · 4 comments
Closed

Apply fb-contrib rules to Unit Tests #18

ganncamp opened this issue Apr 4, 2016 · 4 comments
Assignees

Comments

@ganncamp
Copy link
Contributor

ganncamp commented Apr 4, 2016

In fact since Sonar 3.1 SONAR-1076, everything is in place to be able to report and display a violation on a unit test source file. But it's still the responsibility of each rule engine to decide which rule must be applied to a unit test source file or not.

@h3xstream
Copy link
Member

h3xstream commented Mar 14, 2018

I don't see how this is can be done. 🤔

We are using JavaResourceLocator to obtains the classes in the scope.
https://github.com/spotbugs/sonar-findbugs/blob/master/src/main/java/org/sonar/plugins/findbugs/FindbugsConfiguration.java#L82
If JavaResourceLocator is able to return test classes, this should work transparently.
Aside from blindly looking for test classes, I don't see an API that would return those.

@ganncamp Maybe I am missing something?

@ganncamp
Copy link
Contributor Author

@h3xstream I have no memory of this 😀

However I do know that the SonarJava analyzer makes a distinction between which rules are applied to source files and which to test files. I can't tell you off-hand how, but I'm sure you could that that info on the Google Group.

@h3xstream
Copy link
Member

Thanks, @ganncamp for the response.

I was unsure if sonar-java was getting only the test sources files or also at the binaries.
I did a quick search and found that sonar-java did both. (at first glance)
https://github.com/SonarSource/sonar-java/blob/0d545786c262e5ec0aa4e14f0763ef98ec670c37/java-frontend/src/main/java/org/sonar/java/JavaTestClasspath.java#L46-L51

@gtoison
Copy link
Contributor

gtoison commented Feb 12, 2023

This should be fixed in version 4.2.3 (just released)
Note that the fix needs the SonarQube version to be >= 9.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants