-
Notifications
You must be signed in to change notification settings - Fork 12
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
Feat/custom assertions #110
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: kpoorman <kjp@codefriar.com>
introduces an Org level Assert class that passes through the standard Assert methods by calling `System.Assert.MethodName`. This includes a number of example custom assertions that can all be used by calling Assert.MethodName Signed-off-by: kpoorman <kjp@codefriar.com>
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #110 +/- ##
=======================================
Coverage 95.00% 95.00%
=======================================
Files 32 32
Lines 2002 2002
=======================================
Hits 1902 1902
Misses 100 100
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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.
This class name requires all other Assert
statements to use System.Assert
? If so, it probably needs a new name.
It doesn’t! That’s it’s beauty
…On Oct 4, 2023 at 09:15 -0700, David Schach ***@***.***>, wrote:
@dschach requested changes on this pull request.
This class name requires all other Assert statements to use System.Assert? If so, it probably needs a new name.
In force-app/main/default/classes/test utilities/Assert.cls:
> @@ -0,0 +1,330 @@
+/**
+ * @description Assert class 'shadows' the System.Assert class allowing us to add custom assertion methods accessed
+ * via the static Assert.* methods. This allows us to add custom assertion methods that are more readable and provide
+ * more flexibility and functionality than the standard System.Assert methods. Ultimately the goal is to provide
+ * end-developers with a more readable and flexible way to write assertions.
+ */
***@***.***('PMD.ExcessivePublicCount, PMD.ExcessiveParameterList')
+public with sharing class Assert {
If this class requires all other tests to use System.Assert, then Assert is probably not a good name for the class.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Signed-off-by: kpoorman <kjp@codefriar.com>
introduces an Org level Assert class that passes through the standard Assert methods by calling `System.Assert.MethodName`. This includes a number of example custom assertions that can all be used by calling Assert.MethodName Signed-off-by: kpoorman <kjp@codefriar.com>
9321f4a
to
8ed10a6
Compare
Adding the new Assert method isNotJanky. Hint. if you have to ask, it is. Signed-off-by: kpoorman <kjp@codefriar.com>
Adding the new Assert method isNotJanky. Hint. if you have to ask, it is. Signed-off-by: kpoorman <kjp@codefriar.com>
…ApexKit into feat/CustomAssertions
Signed-off-by: kpoorman <kjp@codefriar.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
Signed-off-by: kpoorman <kjp@codefriar.com>
And CI-pr.yml Signed-off-by: kpoorman <kjp@codefriar.com>
that has 4 parameters. Signed-off-by: kpoorman <kjp@codefriar.com>
WalkthroughThis pull request introduces a new Changes
Uplevel your code reviews with CodeRabbit ProCodeRabbit ProIf you like this project, please support us by purchasing the Pro version. The Pro version has advanced context, superior noise reduction and several proprietary improvements compared to the open source version. Moreover, CodeRabbit Pro is free for open source projects. |
@dschach - I've refactored this into a new class name and reverted the shadowing work. It shows I have an outstanding request for change, but I can't find it. Thoughts on this? |
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.
Files selected (4)
- docs/CAssert.md (1)
- docs/home.md (1)
- force-app/main/default/classes/test utilities/CAssert.cls (1)
- force-app/main/default/classes/test utilities/CAssert.cls-meta.xml (1)
Files skipped from review due to trivial changes (3)
- docs/home.md
- force-app/main/default/classes/test utilities/CAssert.cls
- force-app/main/default/classes/test utilities/CAssert.cls-meta.xml
Review comments generated (1)
- Review: 0
- LGTM: 1
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
Signed-off-by: kpoorman <kjp@codefriar.com>
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.
Files selected (49)
- docs/BulkCallable.md (2)
- docs/CanTheUser.md (24)
- docs/CanTheUserTests.md (1)
- docs/CustomInvocable.md (5)
- docs/ExampleQueueableProcessSteps.md (1)
- docs/FF.md (3)
- docs/FailsafeExceptionHandler.md (1)
- docs/FeatureFlag.md (6)
- docs/FeatureFlagCommonTests.md (4)
- docs/FeatureFlagDataProvider.md (5)
- docs/HttpCalloutMockFactory.md (2)
- docs/IdFactory.md (6)
- docs/Log.md (1)
- docs/LogMessage.md (1)
- docs/LogTriggerHandler.md (3)
- docs/MetadataTriggerFramework.md (3)
- docs/MetadataTriggerQueryService.md (3)
- docs/MethodSignature.md (8)
- docs/MockedMethod.md (16)
- docs/OrgShape.md (5)
- docs/Ouroboros.md (2)
- docs/OuroborosFinalizer.md (1)
- docs/OuroborosTests.md (1)
- docs/Polyfills.md (10)
- docs/Query.md (1)
- docs/QueueableProcess.md (3)
- docs/QueueableProcessDataProvider.md (1)
- docs/QueueableProcessTests.md (1)
- docs/QuiddityGuard.md (2)
- docs/RestClient.md (1)
- docs/RestClientLib.md (13)
- docs/RestLib.md (1)
- docs/RestLibApiCall.md (1)
- docs/SOQL.md (1)
- docs/SOQLAgregate.md (1)
- docs/SOSL.md (1)
- docs/Safely.md (12)
- docs/SampleHandler.md (3)
- docs/Stub.md (9)
- docs/StubUtilities.md (2)
- docs/TestFactory.md (16)
- docs/TriggerContext.md (1)
- docs/TriggerFramework.md (3)
- docs/TriggerFrameworkLoopCount.md (1)
- docs/UFInvocable.md (7)
- docs/ULID.md (3)
- docs/UniversalBulkInvocable.md (2)
- docs/UniversalFlowInputOutput.md (1)
- docs/UniversalInvocable.md (2)
Files ignored due to filter (1)
- config/project-scratch-def.json
Files not summarized due to errors (1)
- docs/CanTheUser.md (diff tokens exceeds limit)
Files not reviewed due to errors (12)
- docs/HttpCalloutMockFactory.md (no response)
- docs/FeatureFlagCommonTests.md (no response)
- docs/LogTriggerHandler.md (no response)
- docs/CanTheUser.md (no response)
- docs/MockedMethod.md (no response)
- docs/Query.md (no response)
- docs/QuiddityGuard.md (no response)
- docs/QueueableProcess.md (no response)
- docs/Safely.md (no response)
- docs/TestFactory.md (no response)
- docs/UniversalBulkInvocable.md (no response)
- docs/UniversalInvocable.md (no response)
Files skipped from review due to trivial changes (31)
- docs/CanTheUserTests.md
- docs/CustomInvocable.md
- docs/ExampleQueueableProcessSteps.md
- docs/FF.md
- docs/FailsafeExceptionHandler.md
- docs/FeatureFlag.md
- docs/IdFactory.md
- docs/Log.md
- docs/LogMessage.md
- docs/MetadataTriggerFramework.md
- docs/MethodSignature.md
- docs/OrgShape.md
- docs/Ouroboros.md
- docs/OuroborosFinalizer.md
- docs/Polyfills.md
- docs/QueueableProcessDataProvider.md
- docs/QueueableProcessTests.md
- docs/RestClient.md
- docs/RestClientLib.md
- docs/RestLib.md
- docs/RestLibApiCall.md
- docs/SOQL.md
- docs/SOQLAgregate.md
- docs/SOSL.md
- docs/SampleHandler.md
- docs/Stub.md
- docs/StubUtilities.md
- docs/TriggerContext.md
- docs/TriggerFrameworkLoopCount.md
- docs/ULID.md
- docs/UniversalFlowInputOutput.md
Review comments generated (22)
- Review: 5
- LGTM: 17
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
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.
Files selected (2)
- docs/CAssert.md (1)
- force-app/main/default/classes/test utilities/CAssert.cls (1)
Review comments generated (6)
- Review: 5
- LGTM: 1
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
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.
Files selected (4)
- docs/CAssert.md (1)
- docs/home.md (1)
- force-app/main/default/classes/test utilities/CAssert.cls (1)
- force-app/main/default/classes/test utilities/CAssert.cls-meta.xml (1)
Files ignored due to filter (1)
- config/project-scratch-def.json
Files skipped from review due to trivial changes (1)
- force-app/main/default/classes/test utilities/CAssert.cls-meta.xml
Review comments generated (7)
- Review: 6
- LGTM: 1
Tips
Chat with CodeRabbit Bot (@coderabbitai
)
- Reply on review comments left by this bot to ask follow-up questions. A review comment is a comment on a diff or a file.
- Invite the bot into a review comment chain by tagging
@coderabbitai
in a reply.
Code suggestions
- The bot may make code suggestions, but please review them carefully before committing since the line number ranges may be misaligned.
- You can edit the comment made by the bot and manually tweak the suggestion if it is slightly off.
Pausing incremental reviews
- Add
@coderabbitai: ignore
anywhere in the PR description to pause further reviews from the bot.
### [CAssert](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CAssert) | ||
|
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.
The new CAssert
class is mentioned in the documentation, but there's no description provided for it. It would be helpful to include a brief explanation of what this class does and how it can be used.
### [CAssert](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CAssert)
+ A 'shadow' Assert class that facilitates developers adding custom assertion methods that can still be cleanly read as `Assert.methodName`.
### [CachePartitionType](https://github.com/codefriar/ApexKit/wiki/Miscellaneous/CachePartitionType)
|
||
/** | ||
* @description An assertion to validate that the object is an SObject | ||
* | ||
* @param obj Object - the object to validate | ||
* @param msg String - the message to display if the assertion fails | ||
*/ | ||
public static void isSObject(Object obj, String msg) { | ||
System.Assert.isInstanceOfType(obj, SObject.class, msg); | ||
} | ||
|
||
/** | ||
* @description An assertion to validate that the exception is of the expected type | ||
* | ||
* @param incomingException Exception - the exception to validate | ||
* @param expectedExceptionType Type - the expected type of the exception | ||
* @param msg String - the message to display if the assertion fails | ||
*/ | ||
public static void caughtExpectedException( | ||
Exception incomingException, | ||
Type expectedExceptionType, | ||
String msg | ||
) { | ||
System.Assert.isInstanceOfType( | ||
incomingException, | ||
expectedExceptionType, | ||
msg | ||
); | ||
} | ||
|
||
/** | ||
* @description An assertion to validate that the exception is of the expected type and contains the expected | ||
* message | ||
* | ||
* @param incomingException Exception - the exception to validate | ||
* @param expectedExceptionType Type - the expected type of the exception | ||
* @param expectedExceptionMessage String - A string that must exist in the resulting exception message | ||
* @param msg String - the message to display if the assertion fails | ||
*/ | ||
public static void caughtExpectedException( | ||
Exception incomingException, | ||
Type expectedExceptionType, | ||
String expectedExceptionMessage, | ||
String msg | ||
) { | ||
System.Assert.isInstanceOfType( | ||
incomingException, | ||
expectedExceptionType, | ||
msg | ||
); | ||
System.Assert.isTrue( | ||
incomingException.getMessage() | ||
.containsIgnoreCase(expectedExceptionMessage), | ||
msg | ||
); | ||
} | ||
|
||
/** | ||
* @description An assertion that validates the given value is within a given range | ||
* | ||
* @param value Integer - the value to validate | ||
* @param min Integer - the minimum value the value must be | ||
* @param max Integer - the maximum value the value must be | ||
* @param msg String - the message to display if the assertion fails | ||
*/ | ||
public static void isInRange( | ||
Integer value, | ||
Integer min, | ||
Integer max, | ||
String msg | ||
) { | ||
System.Assert.isTrue(value >= min && value <= max, msg); | ||
} | ||
|
||
/** | ||
* @description An Assertion that validates that LogEvent__c records were generated. | ||
* Note: this relies on the Log class that's part of ApexKit | ||
* | ||
* @param msg String - the message to display if the assertion fails | ||
*/ | ||
public static void logsWereGenerated(String msg) { | ||
Integer logEvents = [ | ||
SELECT COUNT() | ||
FROM LogEvent__c | ||
WITH SYSTEM_MODE | ||
]; | ||
System.Assert.isTrue(logEvents > 0, msg); | ||
} | ||
|
||
/** | ||
* @description An assertion that validates that LogEvent__c records were generated. | ||
* Note this relies on the Log class that's part of ApexKit. This method override accepts no parameters | ||
* but delegates to the variant above by specifying a default message. | ||
*/ | ||
public static void logsWereGenerated() { | ||
logsWereGenerated( | ||
'Though expected, no log events were generated - if youre not using test.StopTest the events will never publish' | ||
); | ||
} | ||
} |
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.
public static void isNotJanky(String msg) { | ||
System.Assert.fail(msg); | ||
} |
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.
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.
@codefriar CodeRabbit wants to know if this method is some kind of joke.
Integer logEvents = [ | ||
SELECT COUNT() | ||
FROM LogEvent__c | ||
WITH SYSTEM_MODE | ||
]; | ||
System.Assert.isTrue(logEvents > 0, msg); |
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.
In the logsWereGenerated
method, you're querying all LogEvent__c
records in the system. This could potentially return a large number of records and consume a lot of resources, especially in a production environment. It would be better to filter the query based on specific criteria relevant to the test context.
logsWereGenerated( | ||
'Though expected, no log events were generated - if youre not using test.StopTest the events will never publish' | ||
); | ||
} |
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.
Approved |
Adds a 'shadow' Assert class that facilitates developers adding custom assertion methods that can still be cleanly read as
Assert.methodName
Closes #104
Summary by CodeRabbit
Assert
class with custom assertion methods for various conditions, enhancing the testing capabilities.