+ Start a Discussion
vijaya kudupudivijaya kudupudi 

How to cover wrapper class coding inside test class ?

Hi all,

I am writing a test class. Wrapper class variable inside the method is not getting coverage. Bellow is my code. Bellow having my code. Fro line 22 to 30 didn't cover and 32 to 44 didn't cover.
 
public void GoToCart(){
    SearchRend=false;
    productRend=true;
    RendR = false; 

    // Insert Quote 
    QuoteVar = new Quote();
    QuoteProductList = new List<Quote_Product__c>();
    QuoteVar.Name=opp.Name;
    QuoteVar.OpportunityID=opp.id;
    QuoteVar.Status='Opened';
    insert QuoteVar;
    
    qid=QuoteVar.id;
    QuoteVar=[Select id, name from Quote where id=:qid];

    if(wrapPriceList != null){
    for(wrapPrice wrapPriceObj : wrapPriceList) {  //** Qoute Line Items section
        QuoteProduct = new Quote_product__c();
            if(wrapPriceObj.selected == true) {
            QuoteProduct.Quote__c=QuoteVar.id;
            QuoteProduct.Price_Detail__c=wrapPriceObj.pds.id;
            QuoteProduct.Description__c=wrapPriceObj.pds.partNo__r.part_description__c;
            QuoteProduct.Operating_Model__c=wrapPriceObj.pds.Operating_Model__c;
            QuoteProduct.Buying_Price__c=wrapPriceObj.pds.Buying_Price__c;
            QuoteProduct.Type__c=wrapPriceObj.pds.Type__c;
            QuoteProduct.MSRP__c=wrapPriceObj.pds.MSRP__c;
            QuoteProduct.Insurance__c=wrapPriceObj.pds.Insurance__c;
            QuoteProduct.Insurance_Validity__c='12';
            QuoteProductList.add(QuoteProduct);  
            }
    }}
    if(walitems != null){
    for(WalmartItems it1: walitems){
        QuoteProduct = new Quote_product__c();
          if(it1.selected == true){
           QuoteProduct.Quote__c=QuoteVar.id;
           QuoteProduct.Description__c = it1.item.name;
           //QuoteProduct.Walmart_ItemId__c = it1.item.itemId;
           QuoteProduct.Buying_price__c = it1.item.saleprice;
           QuoteProductList.add(QuoteProduct);
        }
    }
    }else if(searchitems != null){
   for(WalmartItems it1: searchitems){
        QuoteProduct = new Quote_product__c();
          if(it1.selected == true){
           QuoteProduct.Quote__c=QuoteVar.id;
           QuoteProduct.Description__c = it1.item.name;
           //QuoteProduct.Walmart_ItemId__c = it1.item.itemId;
           QuoteProduct.Buying_price__c = it1.item.saleprice;
           QuoteProductList.add(QuoteProduct);
        }
    }}
    insert QuoteProductList;
    
    for(Quote_product__c ql:QuoteProductList ){
         qpid.add(ql.id);
     }
    for(quote_product__c qp:[Select id, name,Buying_Price__c, Quantity__c, Discount__c, Insurance_Amount__c from Quote_product__C where id in :qpid]){
      if(qp.Buying_Price__c == null){
            continue;
      }else{
          NetAmount=NetAmount+qp.Buying_price__c;    
      }
    }
    
    selectedList = new List<price_details__c>();
    for(wrapPrice wrapPriceObj : wrapPriceList) {
            if(wrapPriceObj.selected == true) {
            selectedList.add(wrapPriceObj.pds);
            //NetAmount=NetAmount+wrapPriceObj.pds.Buying_price__c;
            }
    }
    
}

 
Amit Chaudhary 8Amit Chaudhary 8
Please post your full code and full test class
Abhishek_DEOAbhishek_DEO
If your wrapper class is public tne you may create an object of this in Test class at first.

For eg.
Mainclass.wrapperclass wrapobj = new Mainclass.wrapperclass();
// set the other attributes 
vijaya kudupudivijaya kudupudi
Hi Abhishek,

Thank you for given reply. I called wrapper class in my test class as you mentioned and i passed the values to that variables. But, I didn't get any change in my code coverage.
QuoteController.wrapPrice wrap =  new QuoteController.wrapPrice(pd);
    wrap.pds= pd;
    wrap.selected = true;

    qc.GoToCart();
is this correct ?