From d9448f1738f12e7c448cf0e69e5d77f2c895018a Mon Sep 17 00:00:00 2001
From: "Travis CI (pmd-bot)"
And if there is a bug fix for a rule, be it a false positive or a false negative case, should be accompanied +
And if there is a bug fix for a rule, be it a false positive or a false negative case, it should be accompanied with an additional test case, so that the bug is not accidentally reintroduced later on.
All the test classes inherit from net.sourceforge.pmd.testframework.SimpleAggregatorTst
,
+
All the test classes inherit from net.sourceforge.pmd.testframework.PmdRuleTst
,
which provides the seamless integration with JUnit. 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
@@ -1296,7 +1296,7 @@ test case and just execute this one.
The SimpleAggregatorTst
class searches the XML file, that describes the test cases for a certain rule
+
The 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
.
<RuleName>.xml
. Search for a class <Rule Name>Test
to find the
unit test class for the given rule.
+This class inherits from SimpleAggregatorTst
and is located in the package “bestpractices”, since the rule
+
This class inherits from PmdRuleTst
and is located in the package “bestpractices”, since the rule
belongs to the category “Best Practices”:
package net.sourceforge.pmd.lang.java.rule.bestpractices;
-import net.sourceforge.pmd.testframework.SimpleAggregatorTst;
+import net.sourceforge.pmd.testframework.PmdRuleTst;
-public class AbstractClassWithoutAbstractMethodTest extends SimpleAggregatorTst {
+public class AbstractClassWithoutAbstractMethodTest extends PmdRuleTst {
// no additional unit tests
}
<?xml version="1.0" encoding="UTF-8"?>
-<test-data>
+<test-data
+ xmlns="http://pmd.sourceforge.net/rule-tests"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests https://pmd.sourceforge.io/rule-tests_1_0_0.xsd">
+
<test-code reinitializeRule="true" regressionTest="true" useAuxClasspath="true">
<description>Just a description, will be used as the test name for JUnit in the reports</description>
<rule-property name="somePropName">propValue</rule-property> <!-- optional -->
@@ -1526,7 +1533,12 @@ the path “com/example/pmd/ruleset.xml”.
-
-
SimpleAggregatorTst
: This is the base class for the test classes and defines the custom JUnit test runner.
+
PmdRuleTst
: This is the base class for tests in PMD’s code base. It is a subclass of RuleTst
and just
+contains the logic to determine the test resources based on the test class name.
+
+ -
+
SimpleAggregatorTst
: This is a more generic base class for the test classes and defines
+the custom JUnit test runner. It doesn’t register any test cases on its own.
It itself is a subclass of RuleTst
.
-
@@ -1574,7 +1586,7 @@ will be executed twice.