maybe I'm missing something here but I don't see any call to the StatamentController class in the test method...You need to invoke it in order to be executed (tested).
Also, make sure you have test code in specific test classes and not within the controller classes. That besides to be a good pratice it is also good for the liimits (source code limit).
He's correct. It's good to write test methods in test classes. And regarding the coverage, you have prepared the data you'll need for your test class but you haven't invoked the class. That is the reason it is not covering your class code.
Attachment attach=new Attachment(); attach.Name='Unit Test Attachment'; Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body'); attach.body=bodyBlob; attach.parentId=acc.id; insert attach;
List<Attachment> attachments=[select id, name from Attachment where parent.id=:acc.id]; System.assertEquals(1, attachments.size());
ApexPages.StandardController std = new ApexPages.StandardController(acc); StatementController sc = new StatementController(std); sc.attachPdf(); // I guess there are callouts in this method, so you'll need to handle them as per your apex class version }
I still get only 42% of the code coverage after your suggested solution. can ou please suggest where I am lacking now. I can provide you more information if you need that.
hi,
maybe I'm missing something here but I don't see any call to the StatamentController class in the test method...You need to invoke it in order to be executed (tested).
Also, make sure you have test code in specific test classes and not within the controller classes. That besides to be a good pratice it is also good for the liimits (source code limit).
Regards
Manuel
He's correct. It's good to write test methods in test classes. And regarding the coverage, you have prepared the data you'll need for your test class but you haven't invoked the class. That is the reason it is not covering your class code.
static testMethod void testAttachments()
{
Account acc=new Account(Name='test');
insert acc;
Attachment attach=new Attachment();
attach.Name='Unit Test Attachment';
Blob bodyBlob=Blob.valueOf('Unit Test Attachment Body');
attach.body=bodyBlob;
attach.parentId=acc.id;
insert attach;
List<Attachment> attachments=[select id, name from Attachment where parent.id=:acc.id];
System.assertEquals(1, attachments.size());
ApexPages.StandardController std = new ApexPages.StandardController(acc);
StatementController sc = new StatementController(std);
sc.attachPdf(); // I guess there are callouts in this method, so you'll need to handle them as per your apex class version
}
Hi Vishal,
thanks for the reply.
I still get only 42% of the code coverage after your suggested solution. can ou please suggest where I am lacking now. I can provide you more information if you need that.
thanks again