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
John Manager Training DepJohn Manager Training Dep 

Test class for List type get set method?

Hi Team,

I have 2 classes,
public class SelectMultiple{    
    @auraenabled public String label {get; set;}
    @auraenabled public String value {get; set;}
    @auraenabled public boolean selected {get; set;}
    @auraenabled public boolean disabled {get; set;}
}

public class Chroma_Detail {

    @auraenabled public List<SelectMultiple> Sprint {get; set;}  
}
How do I create Test Class to get 100% code coverage for this?
Abdul KhatriAbdul Khatri
You have a very strang request. Seems like you need to understand how test works because normally these should be used in some function or method and you cover those functionalities which automatically cover these classes. Anyway for your help here is the test class. Normally I verify my test classes with assert but in this case I don't see need for that.
 
@isTest
public class Chroma_Detail_Test {

    static testMethod void test_chroma_detail()
    {
        SelectMultiple selectMultiple = new SelectMultiple();
        selectMultiple.disabled = true;
        selectMultiple.label = 'test';
        selectMultiple.selected = true;
        selectMultiple.value = 'test';
        
        Chroma_Detail chromaDetail = new Chroma_Detail();
        chromaDetail.Sprint = new List<SelectMultiple>{selectMultiple};
    }  
}

 
John Manager Training DepJohn Manager Training Dep
Thanks very much. How do i create test class for below?
public class Chroma_Detail
 { 
@auraenabled public Map<String, List<SelectMultiple>> clrup {get; set;} 
}


 
Abdul KhatriAbdul Khatri
Replace Sprint to clrup in the above test class
Abdul KhatriAbdul Khatri
Was this helpful?

Can you mark this as the best?
Ajay K DubediAjay K Dubedi
Hi John,

Test class for List type get set method? 100% code coverage
 
@isTest
private class SelectMultipleTest {
    @isTest static void  SelectMultipleMethod()
    {
        List<SelectMultiple> selectMultipeList = new List<SelectMultiple>();
        SelectMultiple selectMultipleObj = new SelectMultiple();
        selectMultipleObj.label = 'Test';
        selectMultipleObj.value = 'Value';
        selectMultipleObj.selected = true;
        selectMultipleObj.disabled = false;
        selectMultipeList.add(selectMultipleObj);
        Chroma_Detail chromaObj = new Chroma_Detail();
        chromaObj.Sprint = selectMultipeList;        
    }
}

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com