+ Start a Discussion
SFDC_LearnerSFDC_Learner 

Test Class Help

public with sharing class newnewtextboxbox
{
    public void additem()
    {
        newtextboxvalues.add(new newtextbox());
    }
 
   public class newtextbox
   {
   }

   private List<newtextbox> newtextboxvalues;
 
 
   public void setnewtextboxvalues(List<newtextbox> items)
   {
       newtextboxvalues=items;
   }
 
 
   public List<newtextbox> getnewtextboxvalues()
   {
       if(newtextboxvalues==null)
       {
           newtextboxvalues=new List<newtextbox>();
           newtextboxvalues.add(new newtextbox());
       }
       return newtextboxvalues;
   }
  
}

 

 

 

Could you please share the test class for above code............

Best Answer chosen by Admin (Salesforce Developers) 
RArunrajRArunraj

Hi,


Below is the test class for your given Apex class, code coverage is 80%

 

@isTest
private class Testnewnewtextboxbox {
    
    static testmethod void testnewTextbox() {
        newnewtextboxbox txtBoxObj = new newnewtextboxbox();
        List<newnewtextboxbox.newtextbox> innerClassObj = new List<newnewtextboxbox.newtextbox>();
        txtBoxObj.setnewtextboxvalues(innerClassObj);
        txtBoxObj.getnewtextboxvalues();
        txtBoxObj.additem();        
        
       //If you declare the line private List<newtextbox> newtextboxvalues; as public List<newtextbox> newtextboxvalues; uncomment the below 2 lines to get 100% code coverage 
       //txtBoxObj.newtextboxvalues = null;
       //txtBoxObj.getnewtextboxvalues();
    }
}

 

 

Thanks,

Arunraj

All Answers

RArunrajRArunraj

Hi,


Below is the test class for your given Apex class, code coverage is 80%

 

@isTest
private class Testnewnewtextboxbox {
    
    static testmethod void testnewTextbox() {
        newnewtextboxbox txtBoxObj = new newnewtextboxbox();
        List<newnewtextboxbox.newtextbox> innerClassObj = new List<newnewtextboxbox.newtextbox>();
        txtBoxObj.setnewtextboxvalues(innerClassObj);
        txtBoxObj.getnewtextboxvalues();
        txtBoxObj.additem();        
        
       //If you declare the line private List<newtextbox> newtextboxvalues; as public List<newtextbox> newtextboxvalues; uncomment the below 2 lines to get 100% code coverage 
       //txtBoxObj.newtextboxvalues = null;
       //txtBoxObj.getnewtextboxvalues();
    }
}

 

 

Thanks,

Arunraj

This was selected as the best answer
SFDC_LearnerSFDC_Learner

Thanks Boss!!!!!