[test] Consolidate packages, move PmdRuleTst, SimpleAggregatorTst

This commit is contained in:
Andreas Dangel
2024-02-23 13:01:07 +01:00
parent 5c5456a6bf
commit 845154716c
456 changed files with 490 additions and 464 deletions

View File

@ -25,7 +25,7 @@ Each category-ruleset has a single abstract base test class, from which the indi
We have one test class per rule, which executes all test cases for a single rule. The actual test cases are
stored in separate XML files, for each rule a separate file is used.
All the test classes inherit from {% jdoc test::testframework.PmdRuleTst %},
All the test classes inherit from {% jdoc test::test.PmdRuleTst %},
which provides the seamless integration with JUnit5. This base class determines the language, the category name
and the rule name from the concrete test class. It then searches the test code on its own.
E.g. the individual rule test class
@ -41,7 +41,7 @@ test case and just execute this one.
## Where to place the test code
The {% jdoc test::testframework.PmdRuleTst %} class searches the XML file, that describes the test cases
The {% jdoc test::test.PmdRuleTst %} class searches the XML file, that describes the test cases
for a certain rule using the following convention:
The XML file is a test resource, so it is searched in the tree under `src/test/resources`.
@ -76,13 +76,13 @@ see [Using the test framework externally](#using-the-test-framework-externally).
### Test Class: AbstractClassWithoutAbstractMethodTest
This class inherits from {% jdoc test::testframework.PmdRuleTst %} and is located in the package "bestpractices",
This class inherits from {% jdoc test::test.PmdRuleTst %} and is located in the package "bestpractices",
since the rule belongs to the category "Best Practices":
``` java
package net.sourceforge.pmd.lang.java.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class AbstractClassWithoutAbstractMethodTest extends PmdRuleTst {
// no additional unit tests
@ -251,7 +251,7 @@ the rule test manually, as SimpleAggregatorTst will fail to determine it correct
``` java
package com.example.pmd.rules;
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
import net.sourceforge.pmd.test.SimpleAggregatorTst;
class CustomRuleTest extends SimpleAggregatorTst {
@Override
@ -272,19 +272,19 @@ The test data should be placed in an XML file located in "src/test/resources" un
The framework uses the [dynamic test feature](https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests)
of JUnit5 under the hood, among a couple of utility classes:
* {% jdoc test::testframework.PmdRuleTst %}: This is the base class for tests in PMD's code base. It is a subclass of
{% jdoc test::testframework.RuleTst %} and just
* {% jdoc test::test.PmdRuleTst %}: This is the base class for tests in PMD's code base. It is a subclass of
{% jdoc test::test.RuleTst %} and just
contains the logic to determine the test resources based on the test class name.
* {% jdoc test::testframework.SimpleAggregatorTst %}: This is a more generic base class for the test classes.
* {% jdoc test::test.SimpleAggregatorTst %}: This is a more generic base class for the test classes.
It doesn't register any test cases on its own. You can register your own rule tests.
It itself is a subclass of {% jdoc test::testframework.RuleTst %}.
It itself is a subclass of {% jdoc test::test.RuleTst %}.
* The maven module "pmd-test-schema" contains the logic to parse the XML files and provides a
{% jdoc test-schema::test.schema.RuleTestCollection %}. This in turn contains a list of
{% jdoc test-schema::test.schema.RuleTestDescriptor %}s. Each rule test descriptor describes a single test case.
* {% jdoc test::testframework.RuleTst %}: uses the {%jdoc test-schema::test.schema.TestSchemaParser %}
* {% jdoc test::test.RuleTst %}: uses the {%jdoc test-schema::test.schema.TestSchemaParser %}
from module "pmd-test-schema" to parse the test cases, executes each
rule test descriptor and asserts the results. It defines a test method `ruleTests()` which is a test factory
and returns one dynamic test per rule test.

View File

@ -115,9 +115,13 @@ Once you have reviewed your ruleset(s), you can switch to PMD 7.
### I'm using custom rules
#### Testing
Ideally, you have written good tests already for your custom rules - see [Testing your rules](pmd_userdocs_extending_testing.html).
This helps to identify problems early on.
The base test classes {%jdoc test::test.PmdRuleTst %} and {%jdoc test::test.SimpleAggregatorTst %} have been moved out
of package `net.sourceforge.pmd.testframework`. You'll need to adjust your imports.
#### Ruleset XML
The `<rule>` tag, that defines your custom rule, is required to have a `language` attribute now. This was always the
case for XPath rules, but is now a requirement for Java rules.

View File

@ -341,6 +341,13 @@ in the migration guide for details.
* pmd-scala
* {%jdoc scala::lang.scala.cpd.ScalaCpdLexer %} (moved from `net.sourceforge.pmd.lang.scala.cpd.ScalaCpdLexer`)
* {%jdoc scala::lang.scala.cpd.ScalaTokenAdapter %} (moved from `net.sourceforge.pmd.lang.scala.cpd.ScalaTokenAdapter`)
* pmd-test
* {%jdoc test::test.lang.rule.AbstractRuleSetFactoryTest %} (moved from `net.sourceforge.pmd.lang.rule.AbstractRuleSetFactoryTest`)
* {%jdoc test::test.AbstractAntTestHelper %} (moved from `net.sourceforge.pmd.ant.AbstractAntTestHelper`)
* {%jdoc test::test.AbstractLanguageVersionTest %} (moved from `net.sourceforge.pmd.AbstractLanguageVersionTest`)
* {%jdoc test::test.PmdRuleTst %} (moved from `net.sourceforge.pmd.testframework.PmdRuleTst`)
* {%jdoc test::test.RuleTst %} (moved from `net.sourceforge.pmd.testframework.RuleTst`)
* {%jdoc test::test.SimpleAggregatorTst %} (moved from `net.sourceforge.pmd.testframework.SimpleAggregatorTst`)
* pmd-xml
* {%jdoc xml::lang.xml.pom.PomLanguageModule %} (moved from `net.sourceforge.pmd.lang.pom.PomLanguageModule`)
* {%jdoc xml::lang.xml.wsdl.WsdlLanguageModule %} (moved from `net.sourceforge.pmd.lang.wsdl.WsdlLanguageModule`)

View File

@ -7,7 +7,7 @@ package net.sourceforge.pmd.lang.apex;
import java.util.Arrays;
import java.util.Collection;
import net.sourceforge.pmd.AbstractLanguageVersionTest;
import net.sourceforge.pmd.test.AbstractLanguageVersionTest;
class LanguageVersionTest extends AbstractLanguageVersionTest {

View File

@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
import net.sourceforge.pmd.lang.rule.AbstractRuleSetFactoryTest;
import net.sourceforge.pmd.test.lang.rule.AbstractRuleSetFactoryTest;
import net.sourceforge.pmd.lang.rule.RuleSet;
import net.sourceforge.pmd.lang.rule.RuleSetLoader;

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex;
import net.sourceforge.pmd.lang.rule.AbstractRuleSetFactoryTest;
import net.sourceforge.pmd.test.lang.rule.AbstractRuleSetFactoryTest;
class RuleSetFactoryTest extends AbstractRuleSetFactoryTest {
// no additional tests yet

View File

@ -6,7 +6,7 @@ package net.sourceforge.pmd.lang.apex.metrics.impl;
import net.sourceforge.pmd.lang.apex.ast.ApexQualifiableNode;
import net.sourceforge.pmd.lang.ast.Node;
import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
import net.sourceforge.pmd.test.SimpleAggregatorTst;
/**
* Executes the metrics testing rules.

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class ApexAssertionsShouldIncludeMessageTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class ApexUnitTestClassShouldHaveAssertsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
public class ApexUnitTestClassShouldHaveRunAsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class ApexUnitTestMethodShouldHaveIsTestAnnotationTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class ApexUnitTestShouldNotUseSeeAllDataTrueTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class AvoidGlobalModifierTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class AvoidLogicInTriggerTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class DebugsShouldUseLoggingLevelTest extends PmdRuleTst {

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.bestpractices;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class UnusedLocalVariableTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class ClassNamingConventionsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class FieldDeclarationsShouldBeAtStartTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class FieldNamingConventionsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class ForLoopsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class FormalParameterNamingConventionsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class IfElseStmtsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class IfStmtsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class LocalVariableNamingConventionsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class MethodNamingConventionsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class OneDeclarationPerLineTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class PropertyNamingConventionsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.codestyle;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class WhileLoopsMustUseBracesTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.design;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class AvoidDeeplyNestedIfStmtsTest extends PmdRuleTst {
// no additional unit tests

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.apex.rule.design;
import net.sourceforge.pmd.testframework.PmdRuleTst;
import net.sourceforge.pmd.test.PmdRuleTst;
class CognitiveComplexityTest extends PmdRuleTst {
// no additional unit tests

Some files were not shown because too many files have changed in this diff Show More