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
Emilien Guichard 40Emilien 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 :
 
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.
Best Answer chosen by Emilien Guichard 40
NagendraNagendra (Salesforce Developers) 
Hi Emllien,

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:
Test.setMock(HttpCalloutMock.class, new YourHttpCalloutMockImpl());
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.