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
Ashok S 7Ashok S 7 

how can i cover following lines in test class

hai Guys,
i am writing the test class.In my test class i cover all the line except 2 lines.
Apex class calss
------------------------------------
public class Create_Controller {

    private Employee_Information__c emp;
    private ApexPages.standardcontroller cont;
    public Create_Controller(ApexPages.StandardController controller) 
    {
      cont = controller;
      this.emp = (Employee_Information__c)controller.getRecord();  
    }
    
    public pagereference save()
    {
    
          try
          {
             insert emp;
             return new pagereference('/apex/List_Vf_Page');
          
          }
          catch(Exception e)
          {
          
              ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Error,e.getmessage()));
              return null;
          
          }
    
    
        return null;
    
    }

Test class class
---------------------------------------------
@isTest(seealldata=true)
public class Create_Controller_Test
{
     public static testmethod void testinsert()
     {
     
        Employee_Information__c ei = new Employee_Information__c();
        ei.First_Name__c = 'Naveen';
        ei.Middle_Name__c = 'Ashok';
        ei.Last_Name__c = 'Sirivella';
        ei.Date_of_Birth__c = Date.Today();
        ei.Father_Husband_Name__c = 'Lakshmi Pathi';
        ei.Marital_Status__c = 'Single';
        
        insert ei;
        
        Test.startTest();
        
         pagereference pg = page.Create_vf_page;
         test.setcurrentpage(pg);
         
         Apexpages.StandardController sc = new Apexpages.StandardController(ei);
         
          Create_Controller cc = new  Create_Controller(sc);
         
         cc.save();
        
        
        Test.stopTest();
     
     
     
     }
 


}

but following lines are not cover
User-added image

the above lines are not covered 
please help me
 
ManojjenaManojjena
Hi Ashok ,
Check belwo link it wil help !!
http://manojjena20.blogspot.in/2015/06/tips-and-tricks-for-test-class.html

Let me know if it helps !!
Thanks
Manoj
SRKSRK
Try this code
(i have remove the  insert ei from test class, it is failing becuase you are trying to insert the record again in apex class that you alraady inserted in test method)

@isTest(seealldata=true)
public class Create_Controller_Test
{
     public static testmethod void testinsert()
     {
     
        Employee_Information__c ei = new Employee_Information__c();
        ei.First_Name__c = 'Naveen';
        ei.Middle_Name__c = 'Ashok';
        ei.Last_Name__c = 'Sirivella';
        ei.Date_of_Birth__c = Date.Today();
        ei.Father_Husband_Name__c = 'Lakshmi Pathi';
        ei.Marital_Status__c = 'Single';
        
          Test.startTest();
        
         pagereference pg = page.Create_vf_page;
         test.setcurrentpage(pg);
         
         Apexpages.StandardController sc = new Apexpages.StandardController(ei);
         
          Create_Controller cc = new  Create_Controller(sc);
          cc.save();

         Test.stopTest();
      }
}