+ Start a Discussion
SV MSV M 

How to write test class for wrapper class

Hi, Can someone help me with how to write a Test Class for the below Wrapper Class...
public class OppRelatedSolutionsController {
    public List<WrapperClass> wrapList{get;set;}
    public List<Solution__c> selectedRecords{get;set;}
    public OppRelatedSolutionsController(ApexPages.StandardController stdController) {
        wrapList = new List<WrapperClass>();
        for(Solution__c solRecs : [SELECT Name, Amount__c, Expected_Revenue__c FROM Solution__c WHERE Opportunity__c = NULL]) {
            wrapList.add(new WrapperClass(solRecs));
        }
        if(wrapList.size() <= 0) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'No Records found'));
        }
    }
    public pageReference saveRecords() {
        selectedRecords = new List<Solution__c>();
        for(WrapperClass wrapRecs : wrapList) {
            if(wrapRecs.selected == TRUE) {
                wrapRecs.sol.Opportunity__c = ApexPages.currentPage().getParameters().get('id');
                selectedRecords.add(wrapRecs.sol);
            }
        }
        update selectedRecords;
        if(selectedRecords.size() > 0) {
            pageReference ref = new PageReference('/'+ApexPages.currentPage().getParameters().get('id'));
            ref.setRedirect(true);
            return ref;
        }
        return null;
    }
    //Wrapper Class
    public class WrapperClass {
        public Solution__c sol{get;set;}
        public Boolean selected{get;set;}
        public WrapperClass(Solution__c s) {
            sol = s;
            selected = false;
        }
    }
}

I am trying to learn how to write Test Classes. So any response would be appreciated... Thanks in Advance.

 
VinayVinay (Salesforce Developers) 
Check below examples on how to write test class for a wrapper class.

https://www.infallibletechie.com/2014/07/how-to-cover-wrapper-class-in-test.html
https://salesforce.stackexchange.com/questions/87533/writing-test-class-for-wrapper-class

Thanks,