Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Plugin produces 3 false positive for each test method in Spock Tests #21

Open
enolive opened this issue Dec 3, 2019 · 0 comments
Open
Labels
bug Something isn't working

Comments

@enolive
Copy link

enolive commented Dec 3, 2019

note: this is a copy of an issue I've written at the old sonar groovy plugin. As it is stalled and my company migrated to this one, I just copied the text here. I guess the rule names are the same. If not, pls notice me so that I can update the description: pmayweg/sonar-groovy#89

We use the plugin mainly for our tests which are written in the awesome spock framework.

However, we noticed that at least three rules are applied to the test method name that don't make any sense in the context of a test method:

  • grvy:org.codenarc.rule.convention.NoDefRule
  • grvy:org.codenarc.rule.naming.MethodNameRule.fixed
  • grvy:org.codenarc.rule.junit.JUnitPublicNonTestMethodRule

Here is some sample code that produces those issues

@SpringBootTest
class EndpointHealthCheckIntegrationTest extends Specification {
  @Autowired
  private EndpointHealthCheck healthCheck

  def "endpoint is up and running"() {
    when: 'health is queried'
    Health health = healthCheck.health().block()
    then: 'status should be up'
    health.status == Status.UP
  }
}

I resolve those issues as false positives and have to do it for every test method which is kinda annoying. On a side note, the def setup() and def tearDown() methods from Spock produce the NoDef-Rule violation as well, but they are much less annoying, as they are only rarely necessary (as opposed to a test class with usually 5-10 tests).

  • the convention for spock test methods is to use def and write a meaningful name (as GString) instead of a JUnit-style identifier
  • the JUnit rule is applied to this kind of tests (I guess because Spock uses JUnit in the background). It clearly can't identify the method as a test and tells me that all methods but tests should not be public.
@enolive enolive changed the title Plugin produces 3 false positive in Spock Tests Plugin produces 3 false positive for each test method in Spock Tests Dec 3, 2019
@TobiX TobiX added the bug Something isn't working label Dec 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants