You need to sign in to do that
Don't have an account?
Emilien Guichard 40
HttpCallout error System.TypeException: Supplied type is not an interface
I am trying to test an HttpCallout using mocks and I get the following error :
I can't find any documentation on this error and what is causing that, could you please advise ?
Thanks a lot.
System.TypeException: Supplied type is not an interface Stack Trace Class.System.Test.setMock: line 57, column 1 Class.ProjectCalloutServiceTest.testBillingCalloutService: line 15, column 1
@IsTest private class ProjectCalloutServiceTest { @IsTest private static void testBillingCalloutService() { Account a = new Account(Name = 'Acme'); insert a; Opportunity o = new Opportunity(Name='Test', StageName='Submitted Project', AccountId=a.Id, Amount=1000, CloseDate=Date.Today()); insert o; List<Id> oppList = new List<Id>(); oppList.add(o.Id); Test.setMock(ProjectCalloutServiceMock.class, new ProjectCalloutServiceMock()); Test.startTest(); ProjectCalloutService.postOpportunityToPMS(oppList); Test.stopTest(); // runs callout and check results o = [select StageName from Opportunity where id =: o.Id]; System.assertEquals('Submitted Project', o.StageName); }
isTest global class ProjectCalloutServiceMock implements HttpCalloutMock { global HttpResponse respond(HttpRequest req) { // Create a fake response HttpResponse res = new HttpResponse(); res.setHeader('Content-Type', 'application/json'); res.setBody('{"status":"success"}'); res.setStatusCode(200); return res; } }
I can't find any documentation on this error and what is causing that, could you please advise ?
Thanks a lot.
See Testing HTTP Callouts by Implementing the HttpCalloutMock Interface(https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_http_testing_httpcalloutmock.htm) (emphasis added):
For the first argument, pass HttpCalloutMock.class, and for the second argument, pass a new instance of your interface implementation of HttpCalloutMock, as follows: After this point, if an HTTP callout is invoked in test context, the callout is not made and you receive the mock response you specified in the respond method implementation.
Please mark this as solved if it's resolved.
Best Regards,
Nagendra.