在 Apex 单元测试中,为什么 MyConrtoller myCont = new MyController(StandardContoller); 调用设置当前页面?
例如,如果我有这个页面:
<apex:page standardController="DB_Object__c" extensions="MyExtension">
<apex:form id="detail_list">
<apex:detail />
<apex:actionStatus id="readStatus">
<apex:facet name="start">
Loading, please wait...
</apex:facet>
<apex:facet name="stop"><apex:outputPanel >
<apex:commandButton action="{!readData}"
value="Update Data"
rerender="detail_list"
status="readStatus"/>
{!remainingRecords}</apex:outputPanel>
</apex:facet>
</apex:actionStatus>
</apex:form>
</apex:page>
如果我的单元测试创建了这个:
DB_Object__c dbObj = new DB_Object__c();
dbObj.Name = 'test';
dbObj.Setting = 'aSetting';
insert dbObj;
Test.setCurrentPageReference(Page.Demo);
ApexPages.StandardController sc = new ApexPages.StandardController(dbObj);
MyExtension myExt = new MyExtension(sc);
为什么会ApexPages.currentPage().getParameters().get('id');
失败?我要做:
ApexPages.currentPage().getParameters().put('id',dbObj.id);
如果它不做任何事情,传递dbObj
to有什么意义?StandardController
您发送的意图是空白对象并且扩展使用此对象吗?似乎没有很多关于 StandardControllers 和单元测试的文档......
谢谢!