Affects PMD Version: 6.1.0
Rule: JUnitAssertionsShouldIncludeMessage
Additional version:
Description:
With junit 5.1 the assertion message is on the last argument .
Here is the link to the javadoc : https://junit.org/junit5/docs/5.0.0-M3/api/org/junit/jupiter/api/Assertions.html#assertEquals-java.lang.Object-java.lang.Object-java.lang.String-
In my sample, the rule should be ok, but when i check it, i have "JUnit assertions should include a message" exception.
Result files:
<?xml version="1.0" encoding="UTF-8"?> <pmd xmlns="http://pmd.sourceforge.net/report/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd" version="6.1.0" timestamp="2018-03-27T18:48:51.560"> <file name="D:\Project\Java\issuePmd\src\test\java\SimpleTest.java"> <violation beginline="9" endline="9" begincolumn="9" endcolumn="20" rule="JUnitAssertionsShouldIncludeMessage" ruleset="Best Practices" package="test.java" class="SimpleTest" method="simpleMethod" externalInfoUrl="https://pmd.github.io/pmd-6.1.0/pmd_rules_java_bestpractices.html#junitassertionsshouldincludemessage" priority="3"> JUnit assertions should include a message </violation> </file> </pmd>
Code Sample demonstrating the issue:
package test.java; import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.Test; class SimpleTest { @Test public void simpleMethod() { assertEquals(0, 1, "Not equals 0 != 1"); } }
Running PMD through: Gradle
apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'pmd' ext { junitJupiterVersion = '5.1.0' } repositories { mavenLocal() mavenCentral() } pmd{ toolVersion = "6.1.0" ruleSetFiles = files("config/pmd/defaultRuleSet.xml") ruleSets = [] } dependencies { // JUnit Jupiter API and TestEngine implementation testCompile("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}") testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}") } test { useJUnitPlatform() }
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Android Application Rules" xmlns="http://pmd.sf.net/ruleset/1.0.0" xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd" xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd" > <description>Standard rule set</description> <rule ref="category/java/bestpractices.xml" /> </ruleset>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4