-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[apex] ApexUnitTestMethodShouldHaveIsTestAnnotation false positive with helper method #3183
Comments
This PMD rule is not smart enough to understand that the assert is moved into another method. Someone could improve it but then the next person would move the assert to another class and then PMD as a single-file checker would not be able to catch it. So @adangel , @oowekyala I vote for closing this. |
Doesn't #2667 resolve a call graph? If so it's not that unrealistic |
I'm not saying that PMD should detect the assert in the called function (as is the case in #1089) but that the assert in the called function should not make PMD detect that function as a test function, because a function that accepts parameters cannot be a test function. The rule seems to search each function to see if it has an assert call, and if it finds one but that function does not have the isTest annotation, flags it as a problem. IMO an early-exit if the function accepts parameters should be sufficient? |
I'd say to keep this issue open. It's a small improvement, but nevertheless a improvement for the rule. Feel free to contribute. And right, this is about Test Methods should have IsTest annotation and not Test should have asserts. |
Taking into account that the intention behind the rule is to prevent the usage of the |
@jonathanwiesel You're right, that would be a better solution. I've made a PR to that effect - #3272. Unfortunately I'm not sure how to find and fix the tests that are now failing. I'm also unsure that the implementation is a good one - in order to get it to work, I had to use a deprecated/internalonly |
Affects PMD Version:
6.32.0
Rule:
ApexUnitTestMethodShouldHaveIsTestAnnotation
Please provide the rule name and a link to the rule documentation:
https://pmd.github.io/latest/pmd_rules_apex_bestpractices.html#apexunittestmethodshouldhaveistestannotation
Description:
Code Sample demonstrating the issue:
Expected outcome:
In the example given, PMD flags the
checkWork
function as it has aSystem.assert
call within it. Yet actual test methods take no parameters. Flagging this function is unexpected as it is not a test method, and cannot be a test method as it accepts parameters. IMO the rule should be improved to exclude methods with parameters as these cannot be actual test methods.Running PMD through: [CLI | Ant | Maven | Gradle | Designer | Other]
CLI and/or VSCode - same result
The text was updated successfully, but these errors were encountered: