Skip to content

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

@Casara

Description

@Casara

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    a:false-positivePMD flags a piece of code that is not problematic

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions