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

[java] MethodNamingConventions - JUnit 5 method naming not support ParameterizedTest #2528

Closed
Casara opened this issue May 26, 2020 · 1 comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Milestone

Comments

@Casara
Copy link

Casara commented May 26, 2020

Affects PMD Version: 6.24.0

Rule: MethodNamingConventions

Description:

The PMD does not use the junit5TestPattern rule for tests annotated with org.junit.jupiter.params.ParameterizedTest.

Code Sample demonstrating the issue:

pmd.xml:

  <rule ref="category/java/codestyle.xml/MethodNamingConventions">
    <properties>
      <property name="methodPattern" value="[a-z][a-zA-Z0-9]*"/>
      <property name="staticPattern" value="[a-z][a-zA-Z0-9]*"/>
      <property name="nativePattern" value="[a-z][a-zA-Z0-9]*"/>
      <property name="junit3TestPattern"
                value="test_[a-z][a-zA-Z0-9]*(_with(out)?[A-Z0-9][a-zA-Z0-9]*)?_should[A-Z0-9][a-zA-Z0-9]*"/>
      <property name="junit4TestPattern"
                value="test_[a-z][a-zA-Z0-9]*(_with(out)?[A-Z0-9][a-zA-Z0-9]*)?_should[A-Z0-9][a-zA-Z0-9]*"/>
      <property name="junit5TestPattern"
                value="test_[a-z][a-zA-Z0-9]*(_with(out)?[A-Z0-9][a-zA-Z0-9]*)?_should[A-Z0-9][a-zA-Z0-9]*"/>
    </properties>
  </rule>

Test code:

  @ParameterizedTest
  @ValueSource(strings = { "FEMALE", "MALE" })
  public void test_fromValue_withGenderValues_shouldReturnEnumType(final String value) {
    assertNotNull(Gender.fromValue(value));
  }

Problem:

The instance method name 'test_fromValue_withGenderValues_shouldReturnEnumType' doesn't match '[a-z][a-zA-Z0-9]*'

Expected outcome:

  • Does PMD report a violation, where there shouldn't be one? -> false-positive

Running PMD through: Gradle

@Casara Casara added the a:bug PMD crashes or fails to analyse a file. label May 26, 2020
@oowekyala oowekyala added a:false-positive PMD flags a piece of code that is not problematic and removed a:bug PMD crashes or fails to analyse a file. labels Oct 26, 2020
@oowekyala oowekyala added this to the 7.0.0 milestone Nov 11, 2020
oowekyala added a commit to oowekyala/pmd that referenced this issue Nov 11, 2020
@adangel
Copy link
Member

adangel commented Dec 11, 2020

Fixed via #2899 for PMD 7.

@adangel adangel closed this as completed Dec 11, 2020
adangel added a commit that referenced this issue Jan 13, 2023
- #2716 has been done with PMD 6.32.0 already
- #2528 was listed twice
@adangel adangel mentioned this issue Jan 23, 2023
55 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a:false-positive PMD flags a piece of code that is not problematic
Projects
None yet
Development

No branches or pull requests

3 participants