1

I have a Class using MetadataService and different methods of it. I want to create a test class for the same but it is giving an error that my test class have HTTP callouts. I am using the HttpCalloutMock but still it is giving me the same error. The Class is using MetadataService, and it is calling multiple callouts which may be the problem

@isTest
private class CustomLabelHelperTest {

    static testMethod void createServiceTestMethod()
    {  
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        Test.startTest();
        MetadataService.MetadataPort service = CustomLabelHelper.createService();
        Test.stopTest(); 
    }

    static testMethod void readCustomLabelsTestMethod()
    {  
        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());
        Test.startTest();
        Map<String, CustomLabelHelper.CustomLabelData> customLabelDataMap = CustomLabelHelper.readCustomLabels();
        Test.stopTest(); 
    }
}

Here my first method is getting passed but the second method is failing.

1
  • Can you post what the error message is? For all we know, it could be unrelated to the callout
    – mkorman
    Commented Apr 26, 2016 at 8:03

1 Answer 1

1

Are you using raw HTTP Callouts or SOAP calls via WSDL2Apex? The MetadataService.MetadataPort makes me suspect the latter.

In that case, your mock class needs to implement WebServiceMock rather than HttpCalloutMock. Then it will correctly mock the SOAP web service response.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .