怎么写Extension的测试类
2022年09月25日
文章浏览:259

我不知道怎么写Extension的Apex类的TestClass

谁能帮我一下。


下面是我的Apex 类

public with sharing class ExtendObject {
private final SObject so;


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

}
}


还有下面是使用extension类的,Visualforce页面的代码 

<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>


关注 收藏
2023年08月26日
@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();
    }

}


回复