function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Help with code coverage



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.


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');
    insert attach;

    List<Attachment> attachments=[select id, name from Attachment where]; 
    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