You need to sign in to do that
Don't have an account?
Varun Sinha 17
Error while creating a test class for web service
I am writing a test class and I am getting this error: System.TypeException: Methods defined as TestMethod do not support Web service callouts
Here is my Test class
@isTest
public class Test_CSS_SOAPEDS {
@isTest static void testEchoString() {
// This causes a fake response to be generated
String title = 'Customer Name:CSS EDS WS Test ';
String workorder = 'workorder1';
String model = 'null'; //"ISC CM2150"; //"ISB CM850";
String serialNumber = '46826048';
String locale = 'en';
string userGroup=System.Label.UserGroup;
string userName=System.Label.UserName;
string encryptedKey = CSS_SOAPEDS.getgenerateToken(userName,userGroup);
string systemDate;
string token=userName+';'+userGroup+';datetime-'+systemDate;
System.debug('The encryptedKey '+encryptedKey);
System.debug('The title id '+title);
string session = CSS_SOAPEDS.login(encryptedKey,locale);
// Call the method that invokes a callout
Test.setMock(WebServiceMock.class, new EDSwebcalloutMockImpl());
String output = CSS_SOAPEDS.createDS(session,title,serialNumber,model,workorder);
System.debug('The output '+output);
// Verify that a fake result is returned
System.assertEquals('DSBDT3829', output);
}
}
Below is my web service mock class
@isTest
global class EDSwebcalloutMockImpl implements WebServiceMock{
global void doInvoke(
Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
wwwKaidaraCom.createDiagnosticSessionResponse response_elem = new wwwKaidaraCom.createDiagnosticSessionResponse();
wwwKaidaraComKaidaraservice.resultDiagnosticSession dsID = new wwwKaidaraComKaidaraservice.resultDiagnosticSession();
dsID.ID='DSBDT3829';
system.debug('DSBDT3829<><>' + dsID.ID);
response_elem.return_x = dsID;
response.put('response_x', response_elem);
}
}
Can anyone help me with this?
Thank You
Varun Sinha
Here is my Test class
@isTest
public class Test_CSS_SOAPEDS {
@isTest static void testEchoString() {
// This causes a fake response to be generated
String title = 'Customer Name:CSS EDS WS Test ';
String workorder = 'workorder1';
String model = 'null'; //"ISC CM2150"; //"ISB CM850";
String serialNumber = '46826048';
String locale = 'en';
string userGroup=System.Label.UserGroup;
string userName=System.Label.UserName;
string encryptedKey = CSS_SOAPEDS.getgenerateToken(userName,userGroup);
string systemDate;
string token=userName+';'+userGroup+';datetime-'+systemDate;
System.debug('The encryptedKey '+encryptedKey);
System.debug('The title id '+title);
string session = CSS_SOAPEDS.login(encryptedKey,locale);
// Call the method that invokes a callout
Test.setMock(WebServiceMock.class, new EDSwebcalloutMockImpl());
String output = CSS_SOAPEDS.createDS(session,title,serialNumber,model,workorder);
System.debug('The output '+output);
// Verify that a fake result is returned
System.assertEquals('DSBDT3829', output);
}
}
Below is my web service mock class
@isTest
global class EDSwebcalloutMockImpl implements WebServiceMock{
global void doInvoke(
Object stub,
Object request,
Map<String, Object> response,
String endpoint,
String soapAction,
String requestName,
String responseNS,
String responseName,
String responseType) {
wwwKaidaraCom.createDiagnosticSessionResponse response_elem = new wwwKaidaraCom.createDiagnosticSessionResponse();
wwwKaidaraComKaidaraservice.resultDiagnosticSession dsID = new wwwKaidaraComKaidaraservice.resultDiagnosticSession();
dsID.ID='DSBDT3829';
system.debug('DSBDT3829<><>' + dsID.ID);
response_elem.return_x = dsID;
response.put('response_x', response_elem);
}
}
Can anyone help me with this?
Thank You
Varun Sinha
Setup debug logs and it will log what is making the callout.