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
fiona gentryfiona gentry 

How to resolve Illegal assignment from void to System.HttpsResponse in Test class

Hi folks,
How to resolve Illegal assignment from void to System.HttpsResponse in Test class

User-added image 
here is class
// Set mock callout class 
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGeneratorAPI());
        
        // Call method to test.
        // This causes a fake response to be sent
        // from the class that implements HttpCalloutMock. 
        Test.starttest();
        HerokuBanSync basicAcct = new HerokuBanSync();
        basicAcct.getBANInfoUpdate('990135742');
        Test.stoptest();
        
         // Set mock callout class 
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        
        // Call method to test.
        // This causes a fake response to be sent
        // from the class that implements HttpCalloutMock. 
      
        HttpResponse res = basicAcct.getBANInfoUpdate('990135742');
        
        // Verify response received contains fake values
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = res.getBody();
        String expectedValue = '{"GSMStackableSOC__c":"false"}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());




Thanks in advance
Fiona

 
Suraj Tripathi 47Suraj Tripathi 47
Hi fiona gentry,

try to do with this method:-

@isTest
private class CalloutClassTest {
     @isTest static void testCallout() {
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        HttpResponse res = CalloutClass.getInfoFromExternalService();
        String contentType = res.getHeader('Content-Type');
        System.assert(contentType == 'application/json');
        String actualValue = res.getBody();
        String expectedValue = '{"example":"test"}';
        System.assertEquals(actualValue, expectedValue);
        System.assertEquals(200, res.getStatusCode());
    }
}

I hope you find the above solution helpful. If it does, please mark it as the Best Answer to help others too.

Thanks and Regards,
Suraj Tripathi