diff --git a/feed.xml b/feed.xml index 62f5ef5f01..a237ae1c99 100644 --- a/feed.xml +++ b/feed.xml @@ -5,8 +5,8 @@ Intended as a documentation theme based on Jekyll for technical writers documenting software and other technical products, this theme has all the elements you would need to handle multiple products with both multi-level sidebar navigation, tags, and other documentation features. https://pmd.github.io/pmd/ - Sun, 11 Nov 2018 13:29:48 +0000 - Sun, 11 Nov 2018 13:29:48 +0000 + Sun, 11 Nov 2018 23:08:55 +0000 + Sun, 11 Nov 2018 23:08:55 +0000 Jekyll v3.7.4 diff --git a/pmd_userdocs_extending_testing.html b/pmd_userdocs_extending_testing.html index a1f66ad91e..c6d604a119 100644 --- a/pmd_userdocs_extending_testing.html +++ b/pmd_userdocs_extending_testing.html @@ -1269,7 +1269,7 @@ a violation - and a negative test case - a code example, that doesn’t trigger Of course, the more tests, the better the rule is verified. If the rule is more complex or defines properties, with which the behavior can be modified, then these different cases can also be tested.

-

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.

How it works

@@ -1280,7 +1280,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 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.

Where to place the test code

-

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.

@@ -1323,18 +1323,21 @@ src/test/resources/net/sourceforge/pmd/lang/<Language Terse Name>/rule/< Just search in the project for a file <RuleName>.xml. Search for a class <Rule Name>Test to find the unit test class for the given rule. + +

Simple example

Test Class: AbstractClassWithoutAbstractMethodTest

-

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
 }
 
@@ -1350,7 +1353,7 @@ this test class. <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 http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> + xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests https://pmd.sourceforge.io/rule-tests_1_0_0.xsd"> <test-code> <description>concrete class</description> <expected-problems>0</expected-problems> @@ -1449,7 +1452,11 @@ in a “CDATA” section, so that no further XML escapes (entity references such

Complete XML example

<?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.