尝试测试自定义潜在客户转换 Class 但代码覆盖率为 0%

Trying to Test Custom Lead Conversion Class but getting 0% Code Coverage

我正在 Class 下面进行测试,即转换潜在客户,我正在尝试为此编写测试 Class,但此测试 class 甚至没有涵盖 1% 的代码。

global class LeadConversion
{
    Public Id leadId;
    public LeadConversion(ApexPages.StandardController stdController)
    {
        leadId = ApexPages.currentPage().getParameters().get('id');
    }
    public PageReference autoConvert()
    {
        Database.LeadConvert convertLead = new database.LeadConvert();
        convertLead.setLeadId(leadId);
        LeadStatus convertStatus = [Select Id, MasterLabel from LeadStatus where IsConverted=true limit 1];
        convertLead.setConvertedStatus(convertStatus.MasterLabel);
        Database.LeadConvertResult convertLeadResult = Database.convertLead(convertLead);

        //TO get Account ID from Lead Conversion
        Id accountId = convertLeadResult.getAccountId();
        PageReference Page = new PageReference('https://----Here My Org URl---/'+accountId);
        Page.setRedirect(true);
        return Page;
    }
}

测试Class

@isTest
public class TestLeadConversion {
    static testMethod void LeadConvertedTest()
    {
        Lead lead1 = new Lead(LastName='Test',FirstName='Tester',Status='Known',Company='test');
        insert lead1;

        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(lead1.id);
        lc.setConvertedStatus('Closed - Converted');

        Database.LeadConvertResult lcr = Database.convertLead(lc);
        System.assert(lcr.isSuccess()); 
    }
}

使用下面的代码看看是否有效。请记住将 Your_Page_Name 替换为您的页面名称。

@isTest
public class TestLeadConversion {
    static testMethod void LeadConvertedTest()
    {
        //Create New Lead
        Lead lead1 = new Lead(LastName='Test',FirstName='Tester',Status='Known',Company='test');
        insert lead1;

        PageReference pageRef = Page.Your_Page_Name;
        //TO get Account ID from Lead Conversion
        pageRef.getParameters().put('id', lead1.id);

        Test.setCurrentPage(pageRef);
        ApexPages.StandardController sc = new ApexPages.standardController(lead1);
        LeadConversion classController = new LeadConversion(sc);
        System.assertNotEquals(null, classController.autoConvert());
    }
}