Newer Version Available
RTRReportResult.MockException
This class is used to create mock exceptions for the unit test execution.
Namespace
The RTRReportResult.MockException class extends Exception.
The supported modifier is global.
1cgcloudSupported Methods
| Method signature | Description | Version |
|---|---|---|
| RTRReportResult.MockException(String message) | The constructor for creating mock exceptions for the unit test execution.
message: String. The message to return as part of the exception. |
60.0 |
Example Implementation
To unit test error handling scenarios, set up a mock exception to be thrown during execution.
1@IsTest
2 public static void myTestMethod() {
3 // Setup
4
5 // Setup your required data for the test
6
7 // Create a mock RTRReportResult
8 cgcloud.RTRReportResult.MockException mockException = new cgcloud.RTRReportResult.MockException(
9 'Sample Error'
10 );
11
12 // Set the mock in RTRReportResult.execute so the call to this method
13 // returns our mock response
14 cgcloud.RTRReportResult.setMock(new List<Object>{ mockException });
15
16 // Test
17
18 // Run your code to be tested. RTRReportResult.execute call will
19 // throw a CGCloudException with the mock exception message
20
21 // Assert
22
23 // Assert your code is working as expected.
24 }