-
-
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] New Rule - Test Methods Must Be In Test Classes #2317
[apex] New Rule - Test Methods Must Be In Test Classes #2317
Conversation
Sorry to be the bad cop here but I think this is a rule with really little value. Everybody should use the annotation and not the keyword for years. The annotation can only be added to @istest classes. |
Generated by 🚫 Danger |
This comment has been minimized.
This comment has been minimized.
I did this because #639 was open, and felt like something easy to start on. But we can close #639 and abandon this PR too, if you like. I don't necessarily disagree with the bad cop in you, but I DO think that "the Salesforce"-way justifies a rule like this for the following reasons:
Re: |
There are two sides to this rule (and the general idea): In current API versions, the Apex Compiler will reject test method annotations if the class itself is not annotated with @istest. So you won't need any PMD rule because the compiler will find this at compile time. The other aspect is: i'm reviewing implementations or I'm taking over dated codebases from time to time, and one of the first things that I do is running Apex PMD against the codebase. Finding code that still uses ancient API versions that allow for @Testmethod within regular classes (or even "require" these inline tests) would be much easier if there was a rule pointing at these classes. You may argue if this is the primary focus of Apex PMD, and you probably don't need such a rule in a basic / general ruleset, but I think it's handy for retro-analysis. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd be ok with adding this rule as long as we mention the following points in the description:
- new Apex API versions enforce this rule already at compile time
- The rule is mostly useful when dealing with legacy code
...t/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/TestMethodsMustBeInTestClasses
Outdated
Show resolved
Hide resolved
@adangel / @dstdia / @rsoesemann - Better now? |
Let’s add it. It’s just a simple XPath rule so not much code overhead. This is not a rule we need to make pmd more attractive but it’s also doesn’t do any harm. |
@adangel - What is the rule, can I merge it, or will you? |
@noerremark I'll merge it |
Merged - this will be part of PMD 6.22.0 |
Before submitting a PR, please check that:
master
. The PMD team will merge back to support branches as needed../mvnw clean verify
passes. This will build and test PMD, execute PMD and checkstyle rules. Check this for more infoPR Description:
The title pretty must says what this is for. It fixes #639.