1

I am having problem when i am trying to write Test Class for Wrapper Class.

Apex class

public with sharing class InlineCtrl {

    public List<Opportunity> oplist {get;set;}
    public List<WrapperMethod> wrap{get;set;}
    public List<Opportunity> savelist{get;set;}
    public Opportunity opp{get;set;}
    public String opget{get;set;}
  //  public boolean show{get;set;}
    public boolean edit{get;set;}


    integer i=0;
    public InlineCtrl()
    {
        oplist=new List<Opportunity>();
        wrap=new List<WrapperMethod>();

        for(Opportunity o:[Select id,Name,StageName,AccountID from Opportunity])
        {
            WrapperMethod w=new WrapperMethod(o,false,i,false);
            wrap.add(w);
            i++;
        }
        system.debug('--Wrap Size--'+wrap.size());
        System.debug('--In Constructor--');

    }



    public void editview()
    {
      Integer q=Integer.valueof(opget);
       wrap.get(q).selected=true;
       wrap.get(q).editble=true;



    }

    public void saveview()
    {

      Integer q=Integer.valueof(opget);
      update wrap.get(q).opp;
      wrap.get(q).selected=false;
      wrap.get(q).editble=false;
   }

    public void deleteview()
    {

       Integer q=Integer.valueof(opget);
       delete wrap.get(q).opp;
       wrap.remove(q);


    }

    public void cancelview()
    {
       Integer q=Integer.valueof(opget);
       wrap.get(q).selected=false;
       wrap.get(q).editble=false;

    }

    public class WrapperMethod
    {
        public opportunity opp{get;set;}
        Public boolean selected{get;set;}
        public integer index{get;set;}
        public boolean editble{get;set;}

        public WrapperMethod(opportunity o,Boolean s,Integer i,Boolean q)
        {
            opp=o;
            selected=s;
            index=i;
            editble=q;
        }

    }

}

Test Class

@isTest
private class InlineCtrlTest
{



    static testMethod void InlineTest()
    {

        opportunity o=new opportunity(Name='Test');
       Boolean selected;
       Integer index;
       Boolean editble;
       String opget='0';
       List<InlineCtrl.WrapperMethod> w;

       InlineCtrl.WrapperMethod testWrap=new InlineCtrl.WrapperMethod(o,selected=false,index=1,editble=false); 

        InlineCtrl inline=new InlineCtrl();
        inline.editview();

        inline.saveview();
        inline.deleteview();
        inline.cancelview();




    }
}
6
  • 3
    wats the problem ? r u getting any error ? can u post the error and possibly any debug logs Commented Aug 10, 2015 at 6:35
  • There is no error but my problem is how can i access my Methods in testclass Commented Aug 10, 2015 at 6:36
  • I am getting this error Class.InlineCtrlTest.InlineTest: line 20, column 1 Commented Aug 10, 2015 at 6:45
  • 2
    @ShantanuMahajan - when you say "this error" my crystal ball does not understand.....luckily the issue was very obvious..
    – Eric
    Commented Aug 10, 2015 at 6:59
  • @Eric how can i access method Commented Aug 10, 2015 at 7:04

1 Answer 1

4

You are calling it wrong:

Change

InlineCtrl.WrapperMethod testWrap=new InlineCtrl.WrapperMethod(o,selected=false,index=1,editble=false); 

to

InlineCtrl.WrapperMethod testWrap=new InlineCtrl.WrapperMethod(o,false,1,false); 

You have other issue with your test class though. It really does absolutely nothing but cover lines...... You really should be testing business processes and asserting that the results are acceptable using asserts

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .