Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Last active November 30, 2018 13:40
Show Gist options
  • Save swapnilshrikhande/24308e7bbe762b066e95e8be486682f0 to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/24308e7bbe762b066e95e8be486682f0 to your computer and use it in GitHub Desktop.
Test Case Execution Dashboard
ApexClass[] testClasses = [SELECT Id FROM ApexClass WHERE Name LIKE 'EditOpportunityServiceTest'];
ApexTestQueueItem[] queueItems = new List<ApexTestQueueItem>();
for (ApexClass cls : testClasses)
queueItems.add(new ApexTestQueueItem(ApexClassId=cls.Id));
//it will submit them for execution
insert queueItems;
Id recordId = queueItems[0].Id;
queueItems = [Select Id,Status,ExtendedStatus,TestRunResultID from ApexTestQueueItem Where Id=: recordId];
System.debug(queueItems[0].TestRunResultID);
Id runResultId = queueItems[0].TestRunResultID;
System.debug([Select MethodsCompleted,MethodsFailed,Status From ApexTestRunResult Where Id = :runResultId]);
System.debug([Select MethodName,Outcome,Message from ApexTestResult Where ApexTestRunResultId = :runResultId]);
ApexTestRunResult:{MethodsCompleted=0, MethodsFailed=0, Status=Queued, Id=05mg0000000BzRUAA0}
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_apextestqueueitem.htm
Select Id,Status,ExtendedStatus,TestRunResultID from ApexTestQueueItem Where Id='709g0000001ivRzAAI'
//https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_apextestrunresult.htm#topic-title
//Select MethodsCompleted,MethodsFailed,Status From ApexTestRunResult Where Id = '05mg0000000BzKEAA0'
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_apextestresult.htm
Select MethodName,Outcome,Message from ApexTestResult Where ApexTestRunResultId = '05mg0000000BzKEAA0'
Select MethodName,Outcome,Message,ApexTestRunResult.Status from ApexTestResult limit 1
Loading test data from static resources
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_load_data.htm
1. Attach csv to the use case record
2. saving the record should create a static resource based on the naming convention
3. the test method would pickup the static resource based on the naming convention
MetadataService.MetadataPort service = createService();
MetadataService.StaticResource staticResource = new MetadataService.StaticResource();
staticResource.fullName = 'MyResource';
staticResource.contentType = 'text';
staticResource.cacheControl = 'public';
staticResource.content = EncodingUtil.base64Encode(Blob.valueOf('Static stuff'));
MetadataService.AsyncResult[] results = service.create(new List<MetadataService.Metadata> { staticResource });
Create generic fields on use case object to add expected values to assert on.
When record is saved create a static resource for the current record
This static resource will be available to the developer to be used inside the test class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment