Affects PMD Version:
1.04+
Rule:
AtLeastOneConstructor
Description:
PMD complains when no explicit constructor is declared for a class. Including JUnit tests.
Note that JUnit expects tests to feature a public, 0-ary constructor, or else it throws an initialization error. So treating JUnit tests as utility classes with private constructors is not an option.
One could explicitly declare an empty constructor for each JUnit test, but that's wasteful. In any case, Java automatically creates an implicit constructor, so there's really no need for PMD to generate noise about this.
As a workaround, I am disabling the AtLeastOneConstructor rule entirely, in my rulesets.xml:
<rule ref="category/java/codestyle.xml">
<exclude name="AtLeastOneConstructor" />
</rule>
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Gradle
Affects PMD Version:
1.04+
Rule:
AtLeastOneConstructor
Description:
PMD complains when no explicit constructor is declared for a class. Including JUnit tests.
Note that JUnit expects tests to feature a public, 0-ary constructor, or else it throws an initialization error. So treating JUnit tests as utility classes with private constructors is not an option.
One could explicitly declare an empty constructor for each JUnit test, but that's wasteful. In any case, Java automatically creates an implicit constructor, so there's really no need for PMD to generate noise about this.
As a workaround, I am disabling the AtLeastOneConstructor rule entirely, in my rulesets.xml:
Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
Gradle