Мне очень тяжело писать тестовый класс. Расширение позволяет пользователю выбрать несколько записей от дочерних (Contingency__c) и добавить в связанный список родительских (Billing_Change_form__c), где учетная запись одинакова. Он содержит класс-оболочку. Я понятия не имею, как получить какое-либо освещение.
Это тестовый класс, который я придумал до сих пор
@isTest
public class bcfTest {
public static testMethod void adBill(){
Billing_Change_form__c testBill = new Billing_Change_Form__c();
testBill.Name = 'Test name';
insert testBill;
Billing_Change_form__c testBill2 = new Billing_Change_Form__c();
testBill2.Name = 'Test name2';
insert testBill2;
Contingency__c caseTest = new Contingency__c();
caseTest.Name = 'test Case';
caseTest.Contingency__c = 'IN BILLING';
caseTest.VENDOR_INVOICE__r.Account_del__r.id='1234';
insert caseTest;
Contingency__c caseTest2 = new Contingency__c();
caseTest2.Name = 'test Case2';
caseTest2.Contingency__c = 'IN BILLING';
caseTest2.VENDOR_INVOICE__r.Account_del__r.id='5678';
insert caseTest2;
Account accTest = new Account();
accTest.Name = 'Test Account';
insert accTest;
Test.startTest();
PageReference pageRef = Page.bcTest; // Add your VF page Name here
pageRef.getParameters().put('id', String.valueOf(testBill.Id));
Test.setCurrentPage(pageRef);
List<wrapperCase> wrapList = new List<wrapperCase>();
List<Contingency__c> selCase = new List<Contingency__c>();
for(Contingency__c b : [Select id, name,
contingency__c, VENDOR_INVOICE__r.Account_del__r.Id from Contingency__c
where (VENDOR_INVOICE__r.Account_del__r.Id = :accTest.Id) ]){
wrapList.add(New wrapperCase(b));
}
for(wrapperCase WATest: wrapList){
WATest.check = true;
}
System.assertEquals(testBill.Id, caseTest.Bill_Form__c);
System.assertEquals('Test name',testBill.Name);
System.assertEquals('IN BILLING', caseTest.CONTINGENCY__c);
test.stopTest();
}
public class wrapperCase{
public contingency__c con{get;set;}
public boolean check{get;set;}
public wrapperCase(contingency__c c){
con = c;
check = false;
}
}
}
Расширение My Controller:
public with sharing class test2 {
//Declare varialbles
public string lookup{get;set;}
public list<conCase> caseList{get;set;}
public boolean allbool{get;set;}
public string inputValue{get;set;}
public boolean bool{get;set;}
public set<id> caseIds{get;set;}
Billing_Change_form__c[] accID = [Select account__c from
Billing_Change_Form__c where id =
:System.currentPagereference().getParameters().get('id')];
ApexPages.StandardController controller;
//Constructor
public test2(ApexPages.StandardController con){
controller = con;
caseList = new list<conCase>();
bool = false;
caseIds = new Set<id>();
}
//Event on clicking the checkbox
public void inIt(){
List<Contingency__c> selectedCase = new list<Contingency__c>();
lookUp = '';
for(conCase conObj : caseList){
if(conObj.check != False){
system.debug('conObj.con'+ conObj.con);
selectedCase.add(conObj.con);
lookUp += conObj.con.name + ', ';
system.debug('lookup:'+ lookup);
caseIds.add(conObj.con.id);
bool = true;
}
If(conObj.check != true){
caseIds.remove(conObj.con.id); }
}
}
//Displaying the records
public List<conCase> getShow(){
caseList = new list <conCase> ();
for(Contingency__c coObj : [Select id, name,billing_type__c, report_description__c, discovery_amount__c,
billing_begins_date__c, contingency__c, VENDOR_INVOICE__r.Account_del__r.Id from Contingency__c
where (VENDOR_INVOICE__r.Account_del__r.Id = :accID[0].Account__c) AND (Bill_form__c = null)])
{
caseList.add(new conCase(coObj, Bool));
}
return caseList;
}
//Event on saving the selected records
public PageReference mySave(){
list<Contingency__c> updateSelectedCase = new list<Contingency__c>();
id billId = ApexPages.currentPage().getparameters().get('id');
System.debug('Bill ID is' + billID);
for(Contingency__c co:[select id, name, bill_form__c from Contingency__c where id = :caseIds ]){
co.bill_form__c = billId;
updateSelectedCase.add(co);
}
update updateSelectedCase;
return null;
}
//Event When the cancel button is hit
public void closePopup(){
bool = false;
}
public void add(){
bool = true;
}
//Wrapper class for the selected records
public class conCase{
public contingency__c con{get;set;}
public boolean check{get;set;}
public conCase(contingency__c c, boolean boo){
con = c;
check = boo;
}
}
}
Моя страница VisualForce:
<apex:page showHeader="False" standardController="Billing_Change_Form__c"
extensions="test2">
<script>
function closeWindow(){
window.opener.location.href="/{!$CurrentPage.parameters.id}";
window.top.close();
}
</script>
<apex:form >
<apex:PageBlock title="CaseFindings" id="counter">
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!mySave}" onComplete="closeWindow();"/>
<apex:commandButton value="Cancel" onclick="window.top.close();" immediate="true" action="{!closePopup}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!show}" var="e" title="show">
<apex:column >
<apex:inputCheckbox value="{!e.check}" />
<apex:actionSupport event="onclick" action="{!inIt}" rerender="none"/>
</apex:column>
<apex:column value="{!e.con.Name}"/>
<apex:column value="{!e.con.DISCOVERY_AMOUNT__c}"/>
<apex:column value="{!e.con.BILLING_BEGINS_DATE__c}"/>
<apex:column value="{!e.con.REPORT_DESCRIPTION__c}"/>
<apex:column value="{!e.con.CONTINGENCY__c}"/>
</apex:pageBlockTable>
</apex:PageBlock>
</apex:form>
</apex:page>
Надеясь получить стандартное 75% покрытие. Если кто-то может помочь мне с этим, я был бы очень признателен! Спасибо!