function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Krishna Sahu 1Krishna Sahu 1 

I need to write test class with assertion please help me on this

@HttpGet
global static List<Patient_Goal__c> getRecords() {
RestRequest request = RestContext.request;
System.debug('request.requestURI: '+request.requestURI);
System.debug('request.params.get(\'patientId\'): '+request.params.get('patientId'));
String ids = request.params.get('patientId');
System.debug(ids);
List<String> listInvIds = ids.split(',');
List<Patient_Goal__c> result =[SELECT Id , Name,goal__c,CurrencyIsoCode,patient__c
FROM Patient_Goal__c
WHERE patient__c = :listInvIds];
return result;
}
ravi soniravi soni
Hi Krishna,
Find your Test Class with 100% Coverage.
@isTest
public class MainClassTest {
@isTest
    public static void test_unit(){
        Patient_Goal__c PG = new Patient_Goal__c();
        PG.Name = 'Test';
        PG.patient__c = 'test1';
        insert PG;
        
    RestRequest req = new RestRequest();
    req.params.put('patientId', 'test1');
    RestResponse res = new RestResponse();

    RestContext.request = req;
    RestContext.response = res;

    Test.startTest();

  List<Patient_Goal__c> lstPG =  MainClass.getRecords();//ClassName.MethodName();

    Test.stopTest();
        system.assertEquals(lstPG[0].Name, 'Test');

    }
}

don't forget to mark it as best answer.
Thank you
PriyaPriya (Salesforce Developers) 

Hey Krishna,

You can learn from this article :- 

https://developer.salesforce.com/forums/?id=906F00000008pUrIAI

If it helps, kindly mark it as the best answer.

Thank you

Priya Ranjan