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
Varun Sinha 17Varun 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
Paul_BoikoPaul_Boiko
You need to use test.setmock() method to test callouts. Here is good article about this: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_callouts_wsdl2apex_testing.htm
charforcecharforce
You get this error if you make a callout from a test class that does not have a WebServiceMock interface implementation. I'd assume there is a callout happening before you call the Test.setMock(WebServiceMock.class, new EDSwebcalloutMockImpl());

Setup debug logs and it will log what is making the callout.