New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[java] JUnitTestsShouldIncludeAssert false positive #1365

blerner opened this Issue Sep 27, 2018 · 2 comments


None yet
3 participants

blerner commented Sep 27, 2018

Affects PMD Version: 6.7.0

Rule: JUnitTestsShouldIncludeAssert

Description: The following two test cases are identical, but for the precise text of the annotation before them. But they give different warnings in PMD. My students encountered this with PMD v6.2.0, and I've just confirmed locally that it still occurs on 6.7.0.

Code Sample demonstrating the issue:

import org.junit.Test;

class Style {
  // This triggers the JUnitTestsShouldIncludeWarning rule
  @org.junit.Test(expected = IllegalArgumentException.class)
  public void moveOutOfBoundsFrom() {
  // This does not
  @Test(expected = IllegalArgumentException.class)
  public void moveOutOfBoundsFrom() {

Running PMD through: Other (custom too invoking PMD.main programmaticallyl, referencing <rule ref="category/java/bestpractices.xml/JUnitTestsShouldIncludeAssert" /> to load this rule)


This comment has been minimized.


jsotuyod commented Sep 28, 2018

@blerner if I'm reading the code correctly, it should work as long as you provide the auxclasspath (which tools such as Gradle and Maven can do automatically).

The code could be better on our side (simpler and better for these scenarios), but the bottom line remains: for PMD to be most accurate, auxclasspath data has to be provided.

if (name != null && ("Test".equals(name.getImage())
|| name.getType() != null && TypeHelper.isA(name, JUNIT4_CLASS_NAME))) {

can be simplified to:

if (name != null && TypeHelper.isA(name, JUNIT4_CLASS_NAME)) {

which should also work on this scenario.


This comment has been minimized.

blerner commented Sep 28, 2018

Ah! I can do that :) I'm already providing a couple of jars on the auxclasspath (to custom libraries that our courses use); it didn't occur to me to put JUnit's jar on the auxclasspath as well. Thanks for the quick triage.

blerner pushed a commit to blerner/bottlenose that referenced this issue Sep 28, 2018

winder pushed a commit to winder/pmd that referenced this issue Oct 8, 2018

@adangel adangel added the has:pr label Oct 8, 2018

@adangel adangel added this to the 6.9.0 milestone Oct 8, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment