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
VFVF 

code coverage

I have tried writing testcase for below apex code but failed.....How can i cover this piece of code for test coverage please  help me out....

 public void getServiceInputs()
 {
    try
    {
  
CCMDAPIV3.CcmdServicePort ccmdport = new CCMDAPIV3.CcmdServicePort();
        CCMDV3inputparams inputParam=new CCMDV3inputparams();
        this.pUserName = inputParam.userName;
        this.pserviceURL = inputParam.serviceurl; 
        this.managerKey =  inputParam.managerKey;    
        String token = ccmdport.openApiConnection(inputParam.userName, inputParam.password, inputParam.managerKey, inputParam.serviceurl);
   if(token != null)
{

this.pStatus = 'Login Successfull'; 
}
else
{
this.pStatus = 'Login Failed';
}
           
            
    }
    catch(Exception ex)
    {            
        this.pStatus = 'Login Failed';
        pError = 'Error Message: '+ex;
        //ApexPages.addMessages('aa'+ex.ToString());  
        //return null;
    }
    
}

Test code:

CCMDAPIV3.CcmdServicePort ccmdport = new CCMDAPIV3.CcmdServicePort();
token = ccmdport.openApiConnection(userName, 'psword', managerKey, serviceURL);
if(token != null)
{
loginStatus = 'Login Successfull'; 
system.assert(true);
}
else
{
loginStatus = 'Login Failed';
system.assert(false);
}
 
Thanks
shaan 
patrospatros

Is your test code actually wrapped in a testMethod?

 

Your test code doesn't call getServiceInputs(). In order to exercise that method, you need to call it. You might also want to consider adding params to getServiceInputs so you can pass in the name, url, key, etc.