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
vasu takasivasu takasi 

How to cover code of a class that contains integrations

public with sharing class myclass{

    public PageReference myclass() {
     Integrationcrm Ic = new Integrationcrm ();
      Integrationcrm .integrationservice IS = new Integrationcrm .integrationservice ();
       IS.runIntegrationService();
       string s = IS.s;
        return null;
    }
    //-----------------test method----------------
    public static testmethod void test()
    {
         myclass obj2=new myclass() ;
        obj2.myclass(); 
               
    }
}

 

in the above code 

 

 string s = IS.s;
        return null;

is not covering.

sfdcfoxsfdcfox

You cannot use callouts when running test methods, so your code is halting at that point, and the rest of the code isn't executing. You'll have to modify your IntegrationCRM class to avoid making the actual callout and use a dummy response when you are in test mode. There is a system function called Test.isRunningTest() that you should call before attempting to communicate with external servers, and if true, return a dummy response instead of actually calling out.

AmitSahuAmitSahu

For a reference :

 

public with sharing class myclass{
public boolean isTest=false;
public PageReference myclass() {
if(isTest==false)
{
Integrationcrm Ic = new Integrationcrm ();
Integrationcrm .integrationservice IS = new Integrationcrm .integrationservice ();
IS.runIntegrationService();
string s = IS.s;
return null;
}else
{
String x = 'sample string return of the above callout';
}
}
//-----------------test method----------------
public static testmethod void test()
{
isTest=true;
myclass obj2=new myclass() ;
obj2.myclass();

}
}

 

You have to specify that the callout is not made in the testMethod.