Мне нужна помощь для моего тестового класса contoller. Я создал входящий набор изменений в моей Production и исходящий в моей Sandbox. Теперь я нахожусь на этапе перехода от 22% кодового покрытия, по крайней мере, к 75% -ному охвату кода, и не делал этого раньше. Это моя страница VisualForce.Тестирование пользовательского контроллера для visualforce страницы
<apex:page controller="MyDealsheetController" tabStyle="Dealsheet__c">
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Create DealSheet">
<apex:pageBlockButtons >
<apex:commandButton action="{! Addrecord}" value="Create Dealsheet"/>
</apex:pageBlockButtons>
<apex:pageBlockSection columns="2" title="Dealsheet Detail">
<apex:inputField value="{! Dealsheet.Trade_Date__c }"/>
<apex:inputField value="{! Dealsheet.Buy_Sell__c }"/>
<apex:selectList size="1" value="{! Dealsheet.Counter_Party__c}" multiselect="false">
<apex:selectOptions value="{!CPList}"></apex:selectOptions>
</apex:selectList>
<apex:selectList size="1" value="{! Dealsheet.Pipe_Line__c}" multiselect="false">
<apex:selectOptions value="{!PipelineList}"></apex:selectOptions>
</apex:selectList>
<apex:inputField value="{! Dealsheet.Start_Date__c }"/>
<apex:inputField value="{! Dealsheet.End_Date__c }"/>
<apex:inputField value="{! Dealsheet.Broker__c }"/>
<apex:inputField value="{! Dealsheet.Brokerage_Per_MMBTU__c }"/>
<apex:inputField value="{! Dealsheet.CP_Trader__c }"/>
<apex:inputField value="{! Dealsheet.CP_Confirm_Email__c }"/>
<apex:inputField value="{! Dealsheet.Deal_Type__c }"/>
<apex:inputField value="{! Dealsheet.Delivery_Point__c }"/>
<apex:inputField value="{! Dealsheet.Volume_MMBTU_Per_Day__c }"/>
<apex:inputField value="{! Dealsheet.PriceIndex_Name__c }"/>
<apex:inputField value="{! Dealsheet.Tradebook__c }"/>
</apex:pageBlockSection>
<apex:PageblockSection columns="1" >
<apex:PageBlockSectionItem >
<apex:outputLabel value="Price Type"/>
<apex:actionRegion >
<apex:inputField label="Price Type" value="{!Dealsheet.Price_Type__c}">
<apex:actionSupport event="onchange" reRender="ajaxrequest" />
</apex:inputField>
</apex:actionRegion>
</apex:PageBlockSectionItem>
</apex:PageblockSection>
<apex:outputPanel id="ajaxrequest">
<apex:pageBlockSection rendered="{!Dealsheet.Price_Type__c =='Fixed'}" >
<apex:inputField value="{!Dealsheet.Fixed_Price__c}"/>
</apex:pageBlockSection>
<apex:pageBlockSection rendered="{!Dealsheet.Price_Type__c =='Floating'}" >
<apex:inputField value="{! Dealsheet.Price_Diff__c}" />
</apex:pageBlockSection>
<apex:pageBlockSection columns="1" title="Comments">
<apex:inputField value="{! Dealsheet.Trader_Comments__c }">
</apex:inputField>
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>
Это Visualforce контроллер код -
public class MyDealsheetController {
public Dealsheet__c Dealsheet;
public MyDealsheetController()
{
Dealsheet= new Dealsheet__c();
}
public Dealsheet__c getDealsheet() {
return Dealsheet;
}
public List<selectOption> getCPList() {
List<selectOption> options= new List<selectOption>();
for (CP__c cp :[SELECT Id, Name FROM CP__c])
{
options.add(new selectOption(cp.Id, cp.Name));
}
return options;
}
public List<selectOption> getPipelineList() {
List<selectOption> options1= new List<selectOption>();
for (NGPIPES__c pipe :[SELECT Id, Name FROM NGPIPES__c])
{
options1.add(new selectOption(pipe.Id, pipe.Name));
}
return options1;
}
public List<selectOption> getCTList() {
List<selectOption> options2=new List<selectOption>();
for (CP_Trader__c CT :[SELECT Id, Name FROM CP_Trader__c])
{
options2.add(new selectOption(CT.Id, CT.Name));
}
return options2;
}
public List<selectOption> getDPList() {
List<selectOption> options3= new List<selectOption>();
for (Delivery_Point__c DP :[SELECT Id, Name FROM Delivery_Point__c])
{
options3.add(new selectOption(DP.Id, DP.Name));
}
return options3;
}
public List<selectOption> getBrokerList() {
List<selectOption> options4= new List<selectOption>();
for (CP_Broker__c Br :[SELECT Id, Name FROM CP_Broker__c])
{
options4.add(new selectOption(Br.Id, Br.Name));
}
return options4;
}
public List<selectOption> getPIList() {
List<selectOption> options5=new List<selectOption>();
for (PRICEINDEX__c PI :[SELECT Id, Name FROM PRICEINDEX__c])
{
options5.add(new selectOption(PI.Id, PI.Name));
}
return options5;
}
public PageReference Cancel()
{
PageReference page = new PageReference('/apex/DealsheetController');
page.setRedirect(true);
return page;
}
public PageReference Addrecord()
{
try {
insert(Dealsheet);
PageReference pageRef = ApexPages.currentPage();
pageRef.setRedirect(true);
return pageRef;
}
Catch(System.DmlException e)
{
ApexPages.addMessages(e);
return null;
}
}
}
и этот тест-код -
@isTest
public class TestMyDealsheetController {
static testMethod void VerifyTestMyDealsheetController()
{
Dealsheet__c ds = new Dealsheet__c();
ds.Trade_Date__c=date.parse('01/01/2015');
ds.Buy_Sell__c='Buy';
ds.Counter_Party__c=''
ds.Start_Date__c=date.parse('02/02/2015');
ds.End_Date__c=date.parse('12/12/2015');
ds.Volume_MMBTU_Per_Day__c=11;
test.startTest();
insert(ds);
test.stopTest();
ApexPages.currentPage().getParameters().put('DealsheetController','?');
ApexPages.StandardController stdDS = new ApexPages.StandardController(ds);
MyDealsheetController MyDSController = new MyDealsheetController();
MyDSController.Addrecord();
MyDSController.Cancel();
}
}
Пожалуйста сделайте насущный пожалуйста совет .. С уважением, Deep