You need to sign in to do that
Don't have an account?
Internal Partner
How to write a test class for a webservice callout?
Hi all,
I am struggling trying to fix a test class for an APEX class (WSDL) which has the following form:
My test class is this:
I am getting this error:
I am struggling trying to fix a test class for an APEX class (WSDL) which has the following form:
global class Example { webService static String getUserName(String name) { return UserInfo.getUserEmail(); } }
My test class is this:
@isTest private class Example_Test { @isTest static void Example() { // This causes a fake response to be generated Test.setMock(WebServiceMock.class, new getUserName()); } }
I am getting this error:
System.TypeException: Mock object doesn't implement the supplied interface Class.System.Test.setMock: line 57, column 1 Class.Example_Test.Example: line 5, column 1Any advice would be appreciated :)
try the below code its 100%
All Answers
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm
Change your code as below
Mock webservice class
Test.setMock(WebServiceMock.class, new getUserName());
getUserName --> need to be implemented WebServiceMock
try the below code its 100%