[SalesForce] Need Help for Extension Test Class

I have a generic extention class and a visualforce page I need to write test classes against, but I am stumped. I have tried a few of the examples found here on StackExchange, but with no luck. Any help is greatly appreciated.

Here is my classs:

public with sharing class ExtendObject {
private final SObject so;


public ExtendObject (ApexPages.StandardController controller)
{
this.so = controller.getRecord ();

}
}

And My visualforce page which is a controller extension:

<apex:page standardController="Custom_Object__c" extensions="ExtendObject" showHeader="false" sidebar="false" standardStylesheets="false" >
<apex:tabPanel switchType="client" selectedTab="tab4" id="theTabPanel" rendered="{!Custom_Object__c.Custom_Field__c != null}">
<apex:tab label="Details 4" name="tab4" id="tab4">
<apex:iframe src="http://website.com?this={!Custom_Object__c.Custom_Field__c}&Accept=1" scrolling="true" id="propIframe4"/>

</apex:tab>
<apex:tab label="Details 1" name="tab1" id="tab1">
<apex:iframe src="http://website.com?this={!Custom_Object__c.Custom_Field__c}" scrolling="true" id="propIframe1"/>

</apex:tab>
<apex:tab label="Details 2" name="tab2" id="tab2">
<apex:iframe src="http://website.com?this={!Custom_Object__c.Custom_Field__c}" scrolling="true" id="propIframe2"/>

</apex:tab>
<apex:tab label="Details 3" name="tab3" id="tab3">
<apex:iframe src="http://website.com?this={!Custom_Object__c.Custom_Field__c}" scrolling="true" id="propIframe3"/>

</apex:tab>

<apex:tab label="Details 5" name="tab5" id="tab5">
<apex:iframe src="http://website.com?this={!Custom_Object__c.Custom_Field__c}" scrolling="true" id="propIframe5"/>

</apex:tab>
</apex:tabPanel>
</apex:page>

Best Answer

You'll want to check out the Salesforce reference on Testing Custom Controllers and Controller Extensions, but here's a bare-bones test case to get you started:

@isTest
private class ExtendObjectTest {

    static testmethod void constructorTest() {
        // set up some test data to work with
        Custom_Object__c co = new Custom_Object__c(Name='blah');
        insert co;

        // start the test execution context
        Test.startTest();

        // set the test's page to your VF page (or pass in a PageReference)
        Test.setCurrentPage(Page.WhateverYourPageIsNamed);

        // call the constructor
        ExtendObject controller = new ExtendObject(new ApexPages.StandardController(co));

        // test action methods on your controller and verify the output with assertions
        controller.save();

        // stop the test
        Test.stopTest();
    }

}
Related Topic