测试 class 通过以下 class 插入联系人

test class for inserting contacts through the following class

我有一个 apex class 插入了 contacts.i 写了一个测试 class 因为它正在通过但代码覆盖率是 zero.can 有人建议我错过了? 测试 class: @isTest public class TestReferalAccessclass { 静态 testMethod void ReferalAccessclassMethod() { Test.StartTest(); 联系方式 c=new Contact(FirstName='fname',LastName = 'lname',Email = 'email@gmail.com',Phone = '9743800309'); 插入 c; System.AssertNotEquals(空,c.Id); Test.StopTest();

 }    

}
apex class:
    public without sharing class ReferalAccessclass {
    public String inputID{get; set;}
    public String firstName{get; set;}
    public String lastName{get; set;}
    public String email{get; set;}
    public String phone{get; set;}
    public Decimal exp{get; set;}
    public String location{get; set;}
    public contact con{get;set;}

    Public attachment objAttachment{get; set;}

    public ReferalAccessclass(ApexPages.StandardController controller) 
      { 

    objAttachment = new Attachment();

    }

  public void saveInformation()
{
try{
    IF(inputID != 'NULL'){
    con = [SELECT ID,Name,FirstName,LastName,Email,Phone,Years_of_Experience__c,Location__c FROM Contact where ID =: inputID ];

    con.FirstName = firstName;
    con.LastName = lastName;
    con.Email = email;
    con.Phone = phone; 
    }
    update con;
    objAttachment.ParentId = con.id;
    Insert objAttachment;

   }
  catch(exception e){} 
  ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.FATAL, 'Thank you for your valuable response');

//return 空;

}

}

您没有从测试 class 调用您的实际 class。这就是它不提供代码覆盖率的原因。试试这个测试 class.

@isTest public class TestReferalAccessclass { 
    static testMethod void ReferalAccessclassMethod() { 

        Contact c=new Contact(
            FirstName='fname',
            LastName = 'lname',
            Email = 'email@gmail.com',
            Phone = '9743800309'); 
        insert c; 
        Test.StartTest(); 
        System.AssertNotEquals(Null, c.Id); 

        ApexPages.StandardController sc = new ApexPages.StandardController(c);
        ReferalAccessclass refClass = new ReferalAccessclass(sc);
        refClass.inputID = c.id;
        refClass.firstName = c.id;
        refClass.lastName = c.id;
        refClass.email = c.id;
        refClass.phone = c.id;
        refClass.con = c;
        refClass.saveInformation();

        Test.StopTest();
    }    
}