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 ApexUnitTestClassShouldHaveRunAs #4149 by tprouvot · Pull Request #4150 · pmd/pmd Conversation
|
|
Hi @adangel ! |
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.
Thanks for your PR!
Please have a look at my comments.
Currently the rule basically only checks, whether in the test method at least once System.runAs has been used. Is this sufficient? It's a very simple check... (but ApexUnitTestClassShouldHaveAsserts does only check for at least one assert as well).
Maybe this simple check is enough for the beginning, maybe not - I don't know. That would add up to false-negatives - e.g. Statements that are outside of a RunAs block, but should actually have been inside a RunAs block.
And it will really flag all tests, that don't use System.runAs - maybe there are cases where you don't need a user, since you are testing just some plain logic. That would add up to false-positives.
I'm not an Apex developer, so I can't tell.
The documentation on salesforce also doesn't have a real example, because you won't test a System.debug call as they do in a RunAs... and there are no asserts in the examples as well...
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
…practices/ApexUnitTestClassShouldHaveRunAsRule.java Co-authored-by: Andreas Dangel <[email protected]>
Co-authored-by: Andreas Dangel <[email protected]>
…practices/ApexUnitTestClassShouldHaveRunAsRule.java Co-authored-by: Andreas Dangel <[email protected]>
Hi @adangel thanks for your review ! As you mentioned it, it may exist some cases where we don't need a user to run the test but most of the time we do. I think this version is a good start and we will see if we need to extend the way it works. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…om/tprouvot/pmd into feature/addApexUnitShouldHaveRunAs
There was an error while loading. Please reload this page.
Co-authored-by: Andreas Dangel <[email protected]>
Generated by 🚫 Danger |
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.
LGTM, thanks! 🎉
I think this version is a good start and we will see if we need to extend the way it works.
Yes, let's see how the feedback is.
I'll merge it later today.
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] New rule: ApexUnitTestClassShouldHaveRunAs
There was an error while loading. Please reload this page.