forked from phoedos/pmd
Update release notes, refs #1694
This commit is contained in:
@@ -52,6 +52,12 @@ More information is available in [the user documentation](pmd_userdocs_cpd.html#
|
||||
for try-blocks, that could be changed to a try-with-resources statement. This statement ensures that
|
||||
each resource is closed at the end of the statement and is available since Java 7.
|
||||
|
||||
* The new Apex rule {% rule "apex/bestpractices/ApexAssertionsShouldIncludeMessage" %} (`apex-bestpractices`)
|
||||
searches for assertions in unit tests and checks, whether they use a message argument.
|
||||
|
||||
* The new Apex rule {% rule "apex/bestpractices/ApexUnitTestMethodShouldHaveIsTestAnnotation" %} (`apex-bestpractices`)
|
||||
searches for methods in test classes, which are missing the `@IsTest` annotation.
|
||||
|
||||
#### Modified Rules
|
||||
|
||||
* The Apex rule {% rule "apex/codestyle/MethodNamingConventions" %} (apex-codestyle) has a new
|
||||
@@ -106,6 +112,7 @@ More information is available in [the user documentation](pmd_userdocs_cpd.html#
|
||||
* [#1654](https://github.com/pmd/pmd/pull/1654): \[core] Antlr token filter - [Tomi De Lucca](https://github.com/tomidelucca)
|
||||
* [#1655](https://github.com/pmd/pmd/pull/1655): \[kotlin] Kotlin tokenizer refactor - [Lucas Soncini](https://github.com/lsoncini)
|
||||
* [#1686](https://github.com/pmd/pmd/pull/1686): \[doc] Replaced wrong escaping with ">" - [Himanshu Pandey](https://github.com/hpandeycodeit)
|
||||
* [#1694](https://github.com/pmd/pmd/pull/1694): \[apex] New rules for test method and assert statements - [triandicAnt](https://github.com/triandicAnt)
|
||||
|
||||
{% endtocmaker %}
|
||||
|
||||
|
@@ -9,6 +9,33 @@
|
||||
Rules which enforce generally accepted best practices.
|
||||
</description>
|
||||
|
||||
<rule name="ApexAssertionsShouldIncludeMessage"
|
||||
since="6.13.0"
|
||||
message="Apex test assert statement should make use of the message parameter."
|
||||
class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexAssertionsShouldIncludeMessageRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexassertionsshouldincludemessage">
|
||||
<description>
|
||||
The second parameter of System.assert/third parameter of System.assertEquals/System.assertNotEquals is a message.
|
||||
Having a second/third parameter provides more information and makes it easier to debug the test failure and
|
||||
improves the readability of test output.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
@isTest
|
||||
public class Foo {
|
||||
@isTest
|
||||
static void methodATest() {
|
||||
System.assertNotEquals('123', o.StageName); // not good
|
||||
System.assertEquals('123', o.StageName, 'Opportunity stageName is wrong.'); // good
|
||||
System.assert(o.isClosed); // not good
|
||||
System.assert(o.isClosed, 'Opportunity is not closed.'); // good
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ApexUnitTestClassShouldHaveAsserts"
|
||||
since="5.5.1"
|
||||
message="Apex unit tests should System.assert() or assertEquals() or assertNotEquals()"
|
||||
@@ -34,6 +61,38 @@ public class Foo {
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ApexUnitTestMethodShouldHaveIsTestAnnotation"
|
||||
since="6.13.0"
|
||||
message="Apex test methods should have @isTest annotation."
|
||||
class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexUnitTestMethodShouldHaveIsTestAnnotationRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation">
|
||||
<description>
|
||||
Apex test methods should have @isTest annotation.
|
||||
As testMethod keyword is deprecated, Salesforce advices to use @isTest annotation for test class/methods.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
@isTest
|
||||
private class ATest {
|
||||
@isTest
|
||||
static void methodATest() {
|
||||
}
|
||||
static void methodBTest() {
|
||||
}
|
||||
@isTest static void methodCTest() {
|
||||
System.assert(1==2);
|
||||
}
|
||||
@isTest static void methodCTest() {
|
||||
System.debug('I am a debug statement');
|
||||
}
|
||||
private void fetchData() {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
||||
<rule name="ApexUnitTestShouldNotUseSeeAllDataTrue"
|
||||
since="5.5.1"
|
||||
message="Apex unit tests should not use @isTest(seeAllData = true)"
|
||||
@@ -106,62 +165,6 @@ trigger Accounts on Account (before insert, before update, before delete, after
|
||||
}
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
<rule name="ApexAssertionsShouldIncludeMessage"
|
||||
since="6.13.0"
|
||||
message="Apex test assert statement should make use of the message parameter."
|
||||
class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexAssertionsShouldIncludeMessageRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexassertionsshouldincludemessage">
|
||||
<description>
|
||||
The second parameter of System.assert/third parameter of System.assertEquals/System.assertNotEquals is a message.
|
||||
Having a second/third parameter provides more information and makes it easier to debug the test failure and improves the readability of test output.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
@isTest
|
||||
public class Foo {
|
||||
@isTest
|
||||
static void methodATest() {
|
||||
System.assertNotEquals('123', o.StageName); // not good
|
||||
System.assertEquals('123', o.StageName, 'Opportunity stageName is wrong.'); // good
|
||||
System.assert(o.isClosed); // not good
|
||||
System.assert(o.isClosed, 'Opportunity is not closed.'); // good
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
<rule name="ApexUnitTestMethodShouldHaveIsTestAnnotation"
|
||||
since="6.13.0"
|
||||
message="Apex test methods should have @isTest annotation."
|
||||
class="net.sourceforge.pmd.lang.apex.rule.bestpractices.ApexUnitTestMethodShouldHaveIsTestAnnotationRule"
|
||||
externalInfoUrl="${pmd.website.baseurl}/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation">
|
||||
<description>
|
||||
Apex test methods should have @isTest annotation.
|
||||
As testMethod keyword is deprecated, Salesforce advices to use @isTest annotation for test class/methods.
|
||||
</description>
|
||||
<priority>3</priority>
|
||||
<example>
|
||||
<![CDATA[
|
||||
@isTest
|
||||
private class ATest {
|
||||
@isTest
|
||||
static void methodATest() {
|
||||
}
|
||||
static void methodBTest() {
|
||||
}
|
||||
@isTest static void methodCTest() {
|
||||
System.assert(1==2);
|
||||
}
|
||||
@isTest static void methodCTest() {
|
||||
System.debug('I am a debug statement');
|
||||
}
|
||||
private void fetchData() {
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</example>
|
||||
</rule>
|
||||
|
15
pmd-core/src/main/resources/rulesets/releases/6130.xml
Normal file
15
pmd-core/src/main/resources/rulesets/releases/6130.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<ruleset name="6130"
|
||||
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
|
||||
<description>
|
||||
This ruleset contains links to rules that are new in PMD v6.13.0
|
||||
</description>
|
||||
|
||||
<rule ref="category/apex/bestpractices.xml/ApexAssertionsShouldIncludeMessage"/>
|
||||
<rule ref="category/apex/bestpractices.xml/ApexUnitTestMethodShouldHaveIsTestAnnotation"/>
|
||||
|
||||
</ruleset>
|
||||
|
Reference in New Issue
Block a user