+ Start a Discussion
cmd loadercmd loader 

test coverage not covered 75%

Hi my test coverage class covers only 71%. Please help me out for 75%.

 

My code is

public with sharing class sendquote1 {


public ID quoteId {get;set;}
public String email {get;set;}
public boolean showpop{set;get;}
public sendquote1 ()
{
quoteId =apexpages.currentpage().getparameters().get('id');
system.debug('acid'+quoteId );
}
Blob body;

list<quotedocument> qdlist=new list<quotedocument>();
pagereference p1;
Blob pdfBlob;
public pagereference save()
{

for(quote q:[select id,name from quote where id=:quoteId ])
{
quotedocument qd=new quotedocument();
PageReference pdfPage = Page.quotePDF;
pdfPage.getParameters().put('id',quoteid);
pdfBlob = pdfPage.getContent();
//Attachment a = new Attachment(parentId = q.id, name=q.name + '.pdf', body = pdfBlob);
qd.quoteid=q.id;
qd.document=pdfBlob ;

qdlist.add(qd);
p1=new pagereference('/'+quoteid);
}
insert qdlist;
return p1;
}
private static testMethod void savetest()
{

Account a=new Account(Name='abc');
insert a;
Pricebook2 pb=new Pricebook2(name='sample',isactive=true);
insert pb;
Product2 p = new Product2();
p.Name = 'TEST';
insert p;
OpportunityStage stage=[select Masterlabel from OpportunityStage limit 1];
Opportunity o = new Opportunity();
o.Name='TestOpp';
o.AccountID=a.id;
o.CloseDate=date.today();
o.StageName=stage.masterlabel;
o.Pricebook2Id=pb.id;
insert o;
Quote q = new Quote();
q.opportunityId=o.id;
q.Pricebook2Id=pb.id;
q.name='TestQuote';
insert q;
Quote q1 = new Quote();
q1.opportunityId=o.id;
q1.Pricebook2Id=pb.id;
q1.name='TestQuote';
insert q1;
Blob b = Blob.valueOf('Test Data');
PageReference pref = Page.quotepdf;
pref.getParameters().put('id',q.id);

Test.setCurrentPage(pref);


quotedocument qd1=new quotedocument();
qd1.quoteid=q.id;
qd1.document=b;
insert qd1;
//ApexPages.currentPage().getParameters().put('id', q.id);

sendquote1 s=new sendquote1();

s.save();
}
}

The bold statements are not covered.

 

Thanks

 

Navatar_DbSupNavatar_DbSup

Hi,

 Try the below test method :

 

private static testMethod void savetest()
{

Account a=new Account(Name='abc');
insert a;
Pricebook2 pb=new Pricebook2(name='sample',isactive=true);
insert pb;
Product2 p = new Product2();
p.Name = 'TEST';
insert p;
OpportunityStage stage=[select Masterlabel from OpportunityStage limit 1];
Opportunity o = new Opportunity();
o.Name='TestOpp';
o.AccountID=a.id;
o.CloseDate=date.today();
o.StageName=stage.masterlabel;
o.Pricebook2Id=pb.id;
insert o;
Quote q = new Quote();
q.opportunityId=o.id;
q.Pricebook2Id=pb.id;
q.name='TestQuote';
insert q;
Quote q1 = new Quote();
q1.opportunityId=o.id;
q1.Pricebook2Id=pb.id;
q1.name='TestQuote';
insert q1;
Blob b = Blob.valueOf('Test Data');
PageReference pref = Page.quotepdf;
pref.getParameters().put('id',q.id);

Test.setCurrentPage(pref);


quotedocument qd1=new quotedocument();
qd1.quoteid=q.id;
qd1.document=b;
insert qd1;
//ApexPages.currentPage().getParameters().put('id', q.id);

sendquote1 s=new sendquote1();
s.quoteId=''1234564564578;
s.email='aa657@gamil.com';
s.showpop='true';
s.body=Blob.valueOf('Test Data');
s.pdfBlob=Blob.valueOf('Test Data');
s.p1=pref;
s.save();
}
}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

cmd loadercmd loader

Hi,

 

Still it is 71% only. Please help me.

 

Thanks.

DrBixDrBix

Did you even bother to run your code in the browser and then click on the link to see what lines are covered?  It will show plainly what lines are not covered.