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
Obulesh RajObulesh Raj 

how to write test class for class containing webservice variables

I have a class which contains other classes having webservice variables declared in them. How to write test class for the class?
Balayesu ChilakalapudiBalayesu Chilakalapudi
Use a StaticResourceCalloutMock built-in class to write test class for your webservice like this,
private class CalloutStaticClassTest {
    @isTest static void testCalloutWithStaticResources() {
        // Use StaticResourceCalloutMock built-in class to
        // specify fake response and include response body 
        // in a static resource.
        StaticResourceCalloutMock mock = new StaticResourceCalloutMock();
        mock.setHeader('Content-Type', 'application/json');
        // Set the mock callout mode
        Test.setMock(HttpCalloutMock.class, mock);
        // Call the method that performs the callout
        HTTPResponse res = CalloutStaticClass.getInfoFromExternalService(
        // Verify response received contains values returned by
        // the mock response.
        // This is the content of the static resource.
        System.assertEquals('{"hah":"fooled you"}', res.getBody());
        System.assertEquals('application/json', res.getHeader('Content-Type'));   
Let me know if it helps to resolve your issue.