You need to sign in to do that
Don't have an account?
Terminusbot
MockHttpResponse for @Future Callouts - Test Class
I'm reading through the documentation and the example provide shows the following for creating a test class using MockHttpResponse.
Since my class is @future it does not return anything. How do I approach creating the test class for a callout that does not return anything. I've been reading and see the use of Test.startTest() and Test.stopTest() but not sure where to apply that in my test class.
Thanks for the help.
@isTest private class CalloutClassTest { @isTest static void testCallout() { // 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 = CalloutClass.getInfoFromExternalService(); // Verify response received contains fake values String contentType = res.getHeader('Content-Type'); System.assert(contentType == 'application/json'); String actualValue = res.getBody(); String expectedValue = '{"foo":"bar"}'; System.assertEquals(actualValue, expectedValue); System.assertEquals(200, res.getStatusCode()); } }
Since my class is @future it does not return anything. How do I approach creating the test class for a callout that does not return anything. I've been reading and see the use of Test.startTest() and Test.stopTest() but not sure where to apply that in my test class.
Thanks for the help.
That is due to the fact that HttpResponse res = CalloutClass.getInfoFromExternalService(); is epecting a returned value.