I'm new to development, but Ive spend more than 12 hours trying to figure this out and am tearing my hair out :( I've read callout and webservice testing and dont understand how it works...
So I have this class which I modified from: http://www.valnavjo.com/blog/how-to-create-invoices-using-quote-templates/
and I am not getting the coverage (only 23%) , so please offer any advice on how to proceed forward. Basically, the Webservice method that is called from a custom button on opportunity page to generate an invoice PDF file using quote templates feature.
Below is my test class and areas lacking coverage:
@isTest
public class TestInvoicepdfclass {
static testMethod void testpdfbutton(){
Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true );
insert pb;
Product2 prod = new Product2(Name = 'SLA: Bronze', IsActive = true);
insert prod;
PricebookEntry pbe=new PricebookEntry(unitprice=0.01,Product2Id=prod.Id, Pricebook2Id=Test.getStandardPricebookId(), IsActive= true);
insert pbe;
Test.startTest();
// insert opp
Account acc = new Account (name='Acme');
insert acc;
Opportunity opp= new Opportunity (name='Testopp', Accountid=acc.id, CloseDate= date.today(), StageName='Closed Won', Pricebook2id=Test.getStandardPricebookId());
insert opp;
OpportunityLineItem oppLine = new OpportunityLineItem( pricebookentryid=pbe.Id,TotalPrice=2000, Quantity = 2,Opportunityid = opp.Id);
insert oppLine;
// insert quote
Quote q= new Quote (Name='Testq', Opportunityid=opp.id, QuotetoInvoice__c= True, REP__C= 'AC', Pricebook2id=Test.getStandardPricebookId());
insert q;
//add to list
List<id> oppids= new List<id> ();
oppids.add(opp.Id);
InvoicepdfWsSample.generateInvoicepdf(oppids);
}
}