3

In my Sandbox i have Generated some Apex Classes from WSDL (Synchronous and Asynchronous as default). I have commented out all the async code because i do not use it for the time being, but i don't want to delete it. I have created test class for the synchronous which has 100% coverage.

When i try to deploy to production those 3 Apex Classes (synchronous, synchronousTest,Asyncronous) i get error message for Code Coverage related to the Asynchronous class which is Commented out! Since comments do not count to code coverage why do we get such error message?

Async Class
public class AsyncEa_Covers {
    /*public class CallRsTypeFuture extends System.WebServiceCalloutFuture {
        public ea_Covers.CallRsType getValue() {
            ea_Covers.CallRsType response = (ea_Covers.CallRsType)System.WebServiceCallout.endInvoke(this);
            return response;
        }
    }
    public class AsyncCallImplBindingSOAP11QSPort {
        public String endpoint_x = '...';
        public Map<String,String> inputHttpHeaders_x;
        public String clientCertName_x;
        public Integer timeout_x;
    }*/
}

testclass

@isTest
public class ea_CoversGetControllerTest {
    //To achieve code coverage, empty class constructor of async class is declared in this test class
    AsyncEa_Covers asyncTest = new AsyncEa_Covers();

    //Method to test getCovers method
    @isTest public static void getCoversTest() {
        try{
            //fresh set of Governor Limits
            test.startTest();
            //...do tests...
            test.stopTest();
        } catch (Exception e) {
            //Exception handling logic...
        }
    }
3
  • This happens in SF even for classes that contain only final static variables. The key to test it for full coverage, just call empty class constructor of async class in you test class. When you will need it, then update it with normal tests. Oct 16, 2019 at 10:17
  • I try to do it but the same happens. Maybe i do something wrong. I updated the issue and now i provide the code.. can u help me please ? Oct 16, 2019 at 11:16
  • Sure, have added code in answer. Oct 16, 2019 at 11:42

1 Answer 1

5

Here is how you can manage the full coverage of commented class (for the comments on question).

public class AsyncEa_Covers {

    public AsyncEa_Covers() {}
    /*public class CallRsTypeFuture extends System.WebServiceCalloutFuture {
        public ea_Covers.CallRsType getValue() {
            ea_Covers.CallRsType response = (ea_Covers.CallRsType)System.WebServiceCallout.endInvoke(this);
            return response;
        }
    }
    public class AsyncCallImplBindingSOAP11QSPort {
        public String endpoint_x = '...';
        public Map<String,String> inputHttpHeaders_x;
        public String clientCertName_x;
        public Integer timeout_x;
    }*/
}

And test class:

@isTest
public class ea_CoversGetControllerTest {
    @IsTest
    private static void testAsync() {
        AsyncEa_Covers asyncTest = new AsyncEa_Covers();
    }
}
1
  • Worked like a charm!! Thank you so much for your help!!! Have a good day Marilia:) Oct 16, 2019 at 12:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .