GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [apex] New Rule - Test Methods Must Be In Test Classes by noerremark · Pull Request #2317 · pmd/pmd

Conversation

@noerremark

@noerremark noerremark commented Feb 27, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Before submitting a PR, please check that:

  • The PR is submitted against 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 info

PR Description:
The title pretty must says what this is for. It fixes #639.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@rsoesemann

rsoesemann commented Feb 27, 2020

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ghost

ghost commented Feb 27, 2020

Copy link
Copy Markdown
1 Message
📖 No java rules are changed!

Generated by 🚫 Danger

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@rsoesemann

This comment has been minimized.

Sign in to view
@noerremark

noerremark commented Feb 28, 2020

Copy link
Copy Markdown
Author

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.

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:

  1. I don't get a warning in Illuminated Cloud if I remove @istest from a class with tests. Having this in place may mean that I get that without building.
  2. Since building happens Salesforce-side, it will always be slower than running PMD on local

Re: testMethod is still heavily used in examples in documentation, and I wouldn't be surprised if lots of people out there still uses it.

rsoesemann reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dstdia

dstdia commented Feb 28, 2020

Copy link
Copy Markdown

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.

rsoesemann reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added the a:new-rule Proposal to add a new built-in rule label Feb 29, 2020
adangel
adangel reviewed Feb 29, 2020
View reviewed changes

@adangel adangel left a comment

Copy link
Copy Markdown
Member

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

rsoesemann reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread ...t/resources/net/sourceforge/pmd/lang/apex/rule/errorprone/xml/TestMethodsMustBeInTestClasses Resolved

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel added the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Feb 29, 2020
@noerremark

noerremark commented Feb 29, 2020

Copy link
Copy Markdown
Author

@adangel / @dstdia / @rsoesemann - Better now?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel removed the is:WIP For PRs that are not fully ready, or issues that are actively being tackled label Feb 29, 2020
adangel
adangel approved these changes Feb 29, 2020
View reviewed changes
Brian Nørremark Brian Nørremark
[apex] New Rule - Test Methods Must Be In Test Classes
4f31838
@rsoesemann

rsoesemann commented Feb 29, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@noerremark

noerremark commented Mar 2, 2020

Copy link
Copy Markdown
Author

@adangel - What is the rule, can I merge it, or will you?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel

adangel commented Mar 2, 2020

Copy link
Copy Markdown
Member

@noerremark I'll merge it

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@adangel adangel self-assigned this Mar 2, 2020
@adangel adangel added this to the 6.22.0 milestone Mar 2, 2020
adangel added a commit that referenced this pull request Mar 2, 2020
@adangel
[doc] Update release notes, fixes #639, refs #2317
b50f4f4
@adangel
adangel merged commit 4f31838 into pmd:master Mar 2, 2020
@adangel

adangel commented Mar 2, 2020

Copy link
Copy Markdown
Member

Merged - this will be part of PMD 6.22.0

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

Reviewers

@adangel adangel adangel approved these changes
+1 more reviewer
@dstdia dstdia dstdia left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@adangel adangel

Labels

a:new-rule Proposal to add a new built-in rule

Projects

None yet

Milestone

6.22.0

Development

Successfully merging this pull request may close these issues.

[apex] Test methods should not be in classes other than test classes

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@noerremark @rsoesemann @dstdia @adangel
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.