GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||
GeezerVison is showing github.com — [apex] New Rule - Test Methods Must Be In Test Classes by noerremark · Pull Request #2317 · pmd/pmd 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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Generated by 🚫 Danger |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
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: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem 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:
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
@adangel / @dstdia / @rsoesemann - Better now? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
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. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@adangel - What is the rule, can I merge it, or will you? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@noerremark I'll merge it |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Merged - this will be part of PMD 6.22.0 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
[apex] Test methods should not be in classes other than test classes
There was an error while loading. Please reload this page.