2

I'm getting the flowing error in Webservice test class.

Methods defined as TestMethod do not support Web service callouts?

I think in test execution we need to make a callout or I'm not sure what is wrong with test class. After googled about it I came to know that we need to store a response static resource and make a callout like below.

 StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
 mock.setStaticResource('myStaticResourceName');
 mock.setStatusCode(200);
 mock.setHeader('Content-Type', 'application/json');

In my actual test class, I am doing like below

 test.startTest();
    insert agmnt;
    Test.setMock(WebServiceMock.class, new LeadCreation_Mock());
    NewAssignmentCreation.sendcbp(gm.id, con.id, agmnt.Name,agmnt.Name, con.id);
    test.stopTest();
}

Do we need to call response in test class using the static resource? If Yes, Can anyone help me to how to do that?

3
Test.setMock(WebServiceMock.class, new YourWebServiceMockImpl()); 

SOAP based webservice only supports WebServiceMock class.

You cannot use StaticResourceCalloutMock to test SOAP based webservices.

Refer Test Web Service Callouts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.