+ Start a Discussion
KyoKyo 

I have a problem Testclass Not Error , but 0% CodeCoverage

Not Error , but 0% CodeCoverage 

 

 

public class MassCreation{
    public List<Case> Cases {get; set;}
    
    public MassCreation(){
        Cases = new List<Case>();
        Case CaseAdd = new Case();
        
        if(Apexpages.Currentpage().getParameters().get('ID')!=null) {
            CaseAdd.ContactID = Apexpages.Currentpage().getParameters().get('id');
        }
      
        //accts.add(new Opportunities_Line_Item__c());
        Cases.add(CaseAdd);
        
    }
    public void addrow(){
        Case CaseAdd;
        if (cases.size()>0)
        {
           caseAdd=cases[cases.size()-1].clone(false, true);
        }
        else 
        {
           CaseAdd=new Case();
           if(Apexpages.Currentpage().getParameters().get('ID')!=null)    {
              CaseAdd.ContactID = Apexpages.Currentpage().getParameters().get('id');
           }
         }
         Cases.add(CaseAdd);
        //accts.add(new Opportunities_Line_Item__c());
    }
   public PageReference deleteRow() {
   if (cases.size()>1)
   {
      cases.remove(Cases.size()-1);
   }
 return null;
 }
    public PageReference save(){
        insert Cases;
        PageReference home = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        home.setRedirect(true);
        return home;
    }
    public PageReference Cancel() {
        PageReference returnPage = new PageReference('/' + ApexPages.currentPage().getParameters().get('id'));
        returnPage.setRedirect(true);
        return returnPage;
    }
    }

 

@isTest 
private class TestMassCreation{
    static testMethod void myTest() {
      List<Case > lstILI = new List<Case >();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstILI);
      
      
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      insert objcon;
      
      Case objca = new Case();
      objca.Origin = 'Phone';
      objca.Status = 'Closed';
      insert objca;
      
      
     
    }
}

 Thank you so much.

 

 

Best Answer chosen by Admin (Salesforce Developers) 
kiranmutturukiranmutturu

tryt this 

 

@isTest 
private class TestMassCreation{
    
    static testMethod void myTest() {
      List<Case > lstILI = new List<Case >();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstILI);
      
      
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      insert objcon;
      
      Case objca = new Case();
      objca.Origin = 'Phone';
      objca.Status = 'Closed';
      insert objca;
      
      test.starttest();
      ApexPages.currentPage().getParameters().put('id', objcon.id);
      MassCreation obj = new MassCreation();
      obj.addrow();
      obj.deleteRow();
      obj.save();
      obj.cancel();
      test.stoptest();
     
    }
    
     static testMethod void myTest1() {
     
      MassCreation obj = new MassCreation();
      obj.Cases.clear();
       obj.addrow();
     
     }
    
    
}

 

All Answers

kiranmutturukiranmutturu

tryt this 

 

@isTest 
private class TestMassCreation{
    
    static testMethod void myTest() {
      List<Case > lstILI = new List<Case >();
      ApexPages.StandardSetController sc = new  ApexPages.StandardSetController(lstILI);
      
      
      Account objAcc = new Account();
      objAcc.Name = 'test';
      insert objAcc;
      
      Contact objcon = new Contact();
      objcon.LastName = 'test';
      objcon.AccountID = objAcc.ID;
      insert objcon;
      
      Case objca = new Case();
      objca.Origin = 'Phone';
      objca.Status = 'Closed';
      insert objca;
      
      test.starttest();
      ApexPages.currentPage().getParameters().put('id', objcon.id);
      MassCreation obj = new MassCreation();
      obj.addrow();
      obj.deleteRow();
      obj.save();
      obj.cancel();
      test.stoptest();
     
    }
    
     static testMethod void myTest1() {
     
      MassCreation obj = new MassCreation();
      obj.Cases.clear();
       obj.addrow();
     
     }
    
    
}

 

This was selected as the best answer
KyoKyo

Yes, Perfect !

Thank you kiran.

KyoKyo

I have a question to ask you a lot for the Class of conditions.

 

 

trigger UpdateStatus on Case (Before update) {
    for(Case ca:Trigger.new){
         if(ca.New__c == False && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status != 'New'))
           {          
                if(ca.Status == 'Open 1st Level')
                        {ca.new__c = true;ca.O1L__c = False; ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False;  ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}            
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; }
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; ca.Reso__c = true; ca.Close__c = true;}
                
         } 

         else if(ca.New__c == True && ca.O1L__c == False && ca.O2L__c == False && ca.IP1L__c == False 
         && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && (ca.Status != 'New'))
           {          
                if(ca.Status == 'Open 1st Level')
                        {ca.new__c = true;ca.O1L__c = False; ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False;  ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'Open 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true;ca.O2L__c=False; ca.IP1L__c=False; ca.IP2L__c=False; ca.Reso__c=False; ca.Cen__c=False;}   
                else if(ca.Status == 'In Progress 1st Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true;}   
                else if(ca.Status == 'In Progress 2nd Level')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true;}      
                else if(ca.Status == 'Resolved')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true; }
                else if(ca.Status == 'Closed')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true;}
                else if(ca.Status == 'Cancel')
                        {ca.new__c = true; ca.O1L__c = true; ca.O2L__c = true; ca.IP1L__c = true; ca.IP2L__c = true;  ca.Reso__c = true; ca.Close__c = true;}
                
         } 

 

@isTest
Private Class TestUpdateStatus{
    static testMethod void myTest1() {
            
            Case ca = new Case(Origin = 'Phone',Status = 'Open 1st Level',Function__c = 'CC',Type = 'Inquiry',new__c = true);
            test.startTest();       
            insert ca;
            update ca;
            //Assert your results
            test.stopTest();
    }

   static testMethod void myTest2() {
            
            Case ca = new Case(Origin = 'Phone',Status = 'Open 2nd Level',Function__c = 'CC',Type = 'Inquiry',new__c = true,O1L__c = True);
            test.startTest();       
            insert ca;
            update ca;
            //Assert your results
            test.stopTest();
    }
}

 I  write more TestClass me.

 

Thank you Kiran.