2

I am having trouble with getting one of the Classes to get Code Coverage. Below is the Code:

public class Match 
{                
    @TestVisible public List<Common> Common {get; set;}            
}

Below is the Common Apex Class that is being referenced by my Match Class:

@TestVisible public class Common {

    public String Address {get; set;}
    public String City {get; set;}
    public String FirstName {get; set;}
    public String Id {get; set;}
    public String LastName {get; set;}
    public String MiddleInitial {get; set;}
    public String Phone {get; set;}
    public String PostalCode {get; set;}
    public String RuleName {get; set;}
    public String Score {get; set;}
    public String StateProvince{get; set;}
    public String CompanyName {get; set;}
    public Integer CorporateEmployeesSizeActual{get; set;}      
    public String CorporateEmployeesSizeRange{get; set;}       
    public Integer CorporateSalesVolumeActual{get; set;}    
    public String CorporateSalesVolumeRange{get; set;}    
    public String CreditRatingScore{get; set;}
    public String Gender{get; set;}     
    public Integer LocationEmployeesSizeActual{get; set;}       
    public String LocationEmployeesSizeRange{get; set;}       
    public String PrimaryNaics{get; set;}       
    public String PrimarySic{get; set;}       
    public String Title{get; set;}

    public String BusinessType{get; set;}                        
    public String Franchise{get; set;}   
    public String LocationSalesVolumeActual{get; set;}   
    public String LocationSalesVolumeRange{get; set;}  
    public String TickerSymbol{get; set;}                     

}

The Test Class I have so far looks like this but I get an error Illegal assignment from Common to List:

@IsTest
private class TestClassess
{
    static testmethod void testMatch()
    {   
        Match obj = new Match();

        Common cmn = new Common();
        cmn.Address = 'z';

        obj.Common = cmn;
    }
}

Unfortunately this is not my code but I do need to create a Test Class for it.

Any help would be much appreciated!

Thanks! Martijn

  • 1
    In your test class obj.Common = cmn; is invalid. obj.Common expecting List<Common> but you are assigning a variable of type Common – highfive Apr 28 '16 at 9:12
  • 1
    It's also worth mentioning that you don't need the @TestVisible annotation on public classes and members: if they are public, they are visible already. More importantly, your test is not actually asserting anything. The purpose of a test is not to provide coverage, but to test behaviour, which is done via asserts – mkorman Apr 28 '16 at 9:46
2

In your test class obj.Common = cmn; is invalid. obj.Common expecting List<Common> but you are assigning a variable of type Common. Update your code something as below where it's in type of List<Common>

@IsTest
private class TestClassess
{
    static testmethod void testMatch()
    {   
        Match obj = new Match();

        List<Common> commonList = new List<Common>();
        Common cmn = new Common();
        cmn.Address = 'z';

        commonList.add(cmn);

        obj.Common = commonList;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.