1

Controller :

  public class WizardClass   
  {  
      public Opportunity Oppo{get;set;}  
      public List<Quote> quoteList{get;set;}    

    public WizardClass()
    {
        Oppo = new Opportunity();
        quoteList = new List<Quote>();
        quoteList.add(new quote());
    }

    public void CreateQuote()
    {
        quoteList.add(new quote());
        }

    **public PageReference QuotePage()
    {
        return Page.OppoQuotes;
        }**

    public PageReference Create()
    {
        insert Oppo;   
        **List<Quote> quoList = new List<Quote>();
        for(Quote q : quoteList)
        {
            Quote quo = new Quote();
            quo.OpportunityId = Oppo.id;
            quo.name = q.name;
            quoList.add(quo);
            }
       // q.OpportunityId = Oppo.id;
        insert quoList;
        PageReference newPage = new PageReference('/'+Oppo.id);
        return newPage;
        }**


  }

Test Class :

  @isTest  
  Private class WizardClassTest  
  {  
    static testMethod void unitTest()   
    {    
        Test.starttest() ;  
        Opportunity opp = new opportunity();  
        opp.Name = 'Roy';  
        opp.closeDate = system.today();  
        opp.stageName = 'Prospecting' ;  
        Insert opp;  
        List<Quote> quoteList = new List<Quote>();  
        Quote q = new Quote();  
        q.name = 'Joe';  
        q.opportunityId = opp.Id;  
        quoteList.add(q);  
        Quote quo = new Quote();  
        quo.name = 'Monroe';  
        quo.opportunityId = opp.Id;  
        quoteList.add(quo);  
        insert quoteList;  
        System.assertEquals(2,opp.quotes.size());  
        Test.stoptest();  
    }  
}  

3 Answers 3

1

You should query on quotes before System.assertEquals(2,opp.quotes.size());

1
  • query how? can yo plz tell me...
    – Anzar
    Mar 18, 2016 at 10:16
1

I think is because you dont cover the method. Try add this

@isTest  
Private class WizardClassTest  
{      
static testMethod void unitTest()   
{    
    Test.starttest() ;  
    Account acc = new Account(Name='test acc');
    insert acc;
    Opportunity opp = new opportunity();  
    opp.Name = 'Roy';
    opp.AccountId = acc.id;  
    opp.closeDate = system.today();  
    opp.stageName = 'Prospecting' ;  
    Insert opp;  

    List<Quote> quoteList = new List<Quote>();  
    Quote q = new Quote();  
    q.name = 'Joe';  
    q.opportunityId = opp.Id;  
    quoteList.add(q);  
    Quote quo = new Quote();  
    quo.name = 'Monroe';  
    quo.opportunityId = opp.Id;  
    quoteList.add(quo);  
    insert quoteList;  

    WizardClass wc = new WizardClass();
    quoteList = wc.quoteList;
    System.assertEquals(2,quoteList.size());
    wc.CreateQuote();
    wc.Create();
    wc.QuotePage();  
    Test.stoptest();  
    }  
}  

can you please attach which line its not covered by your code. it will make us easier to help you

5
  • the code coverage has gone to 45% only...can you suggest me something else.
    – Anzar
    Mar 18, 2016 at 10:13
  • try run the test on developer console because you can see the lines of code are covered. Test->New Run->Pick your Test Class->Run->Open your Apex Class on the upper left you can see the coverage of code. see my edited post Mar 18, 2016 at 10:18
  • I have checked there only 10 lines are covered out of 22.I have edited my code and have added ** ** to lines that are not covered .
    – Anzar
    Mar 18, 2016 at 10:24
  • please check my edited code Mar 18, 2016 at 10:34
  • The code coverage has gone to 27%. I have as it is copied your code ..
    – Anzar
    Mar 18, 2016 at 10:37
0
List<Quote> quoList = new List<Quote>();
        for(Quote q : quoteList)
        {
            Quote quo = new Quote();
            quo.OpportunityId = Oppo.id;
            quo.name = q.name;
            quoList.add(quo);
            }
       // q.OpportunityId = Oppo.id;
        insert quoList;
        PageReference newPage = new PageReference('/'+Oppo.id);
        return newPage;
        }

        public PageReference QuotePage()
        {
        return Page.OppoQuotes;
        }
1
  • These lines are not covered in code
    – Anzar
    Mar 18, 2016 at 10:36

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.