Newer Version Available
RTRReportResult.MockScoreCard
This class is used to create mock responses for the unit test execution.
Namespace
The RTRReportResult.MockScoreCard class extends RTRReportResult.ScoreCard.
The supported modifiers are global and virtual.
1cgcloudSupported Methods
| Method signature | Description | Version |
|---|---|---|
| RTRReportResult.MockScoreCard(Map<String, Decimal> kpiValues) | The constructor for creating mock responses for the unit test execution.
kpiValues: Map<String, Decimal> . A map of a KPI name to a decimal value. The mocked value is returned when the getValue method is executed. |
60.0 |
Example Implementation
To unit test a scorecard component, mock the scorecard values using the MockScoreCard class.
1@IsTest
2 public static void myTestMethod() {
3 // Setup
4
5 // Setup your required data for the test
6
7 // Expected RTR Report Filters
8 Map<String, Object> expectedReportFilters = ...
9
10 // Create a mock RTRReportResult
11 cgcloud.RTRReportResult.MockRTRReportResult mockReportResult = new cgcloud.RTRReportResult.MockRTRReportResult(
12 // Create a map with the returned report components
13 new Map<String, cgcloud.RTRReportResult.ReportComponent>{
14 // Flatlist component
15 'ScoreCard' => new cgcloud.RTRReportResult.MockScoreCard(
16 // For KPI, set the values
17 new Map<String, Object>{ 'KPI1' => 123, 'KPI2' => 456 }
18 )
19 }
20 );
21
22 // Set the mock in RTRReportResult.execute so the call to this method
23 // returns our mock response
24 cgcloud.RTRReportResult.setMock(new List<Object>{ mockReportResult });
25
26 // Test
27
28 // Run your code to be tested. RTRReportResult.execute call will
29 // return the mock result
30
31 // Assert
32
33 // Assert your code is working as expected.
34
35 // You can also validate RTRReportResult.execute was called with the expected
36 // parameters
37 system.assertEquals('0001', mockReportResult.getSalesOrg());
38 system.assertEquals('MySampleReport', mockReportResult.getReportName());
39 system.assertEquals(expectedReportFilters, mockReportResult.getFilters());
40 }