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

Test Coverage for VF pages, VF pages as email attachments, and their controllers???

Hi, I'm a bit new when it comes to visualforce and how to release them and their controllers to production.  


Who ever provides me with a reference I can use to create mine I will definitely give kudos to all that help.


Thank you,

Steve Laycock

Best Answer chosen by Admin (Salesforce Developers) 

You don't actually "cover" VF pages, only Apex Code.


Testing the controller is generally in the form of:


@isTest static void test() {
    // Create test data
    Account record = new Account(Name='Test');
    insert record;
    // Create page controller
    PageController controller = new PageController(new ApexPages.StandardController(record));
    // Test the various methods
    Decimal result1 = controller.doSomething1();
    String result2 = controller.doSomething2();
    PageReference result3 = controller.doSomething3();
    // Test the results
    System.assertEquals(5, result1);
    System.assertEquals("Hello World", result2);
    System.assertEquals(result3, Page.NextPage);

Your exact needs will vary, but this pattern will be consistent for every test you write.