+ Start a Discussion
KyoKyo 

TestClass Code Coverage 55%

 

trigger LockStatus on Case (After update) {
    for(Case ca:Trigger.new){
         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')){
            Trigger.new[0].Status.addError('Can not choose less than Open 1st Level');  // Open 1st Level
        } 
        else if(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.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level'))){
            Trigger.new[0].Status.addError('Can not choose less than Open 2nd Level');  // Open 2nd Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == False 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level')) ){
            Trigger.new[0].Status.addError('Can not choose less than In Progress 1st Level'); //In Progress 1st Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == False  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level'))){
            Trigger.new[0].Status.addError('Can not choose less than In Progress 2nd Level'); //In Progress 2nd Level
        }
        else if(ca.New__c == True && ca.O1L__c == True && ca.O2L__c == True && ca.IP1L__c == True 
           && ca.IP2L__c == True  && ca.Reso__c == False && ca.Close__c == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level'))){
            Trigger.new[0].Status.addError('Can not choose less than Resolved'); //Resolved
        }
        else if(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 == False && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level') || (ca.Status == 'Resolved'))){
            Trigger.new[0].Status.addError('Can not choose less than Closed'); //Closed
        }
        else if(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 && ((ca.Status == 'New') || (ca.Status == 'Open 1st Level') || (ca.Status == 'Open 2nd Level') || (ca.Status == 'In Progress 1st Level') || (ca.Status == 'In Progress 2nd Level')  || (ca.Status == 'Resolved') || (ca.Status == 'Closed'))){
            Trigger.new[0].Status.addError('Can not choose less than Cancle'); //Cancel
        }
}
}

 

@isTest
private class TestLockStatus  {
   static testMethod void myUnitTest() {   
      Case ca = new Case(Origin = 'Phone',Status = 'New',Subject = 'A',Type = 'Dummy',New__c = true,O1L__c = False,O2L__c = False,IP1L__c = False,
      IP2L__c = False,Reso__c = False,Close__c = False);
      test.startTest();
             try {      insert ca; update ca;    }
                 catch (Exception e) {                
                        System.debug('Can not choose less than Open 1st Level'); 
                    } 
       test.stopTest();  
     }

 Thank you so much.

 

Rahul S.ax961Rahul S.ax961

You have to create Multiple cases in test coverage, which satisfies each of your condition