I am new to coding and am using Salesforce. I need help understanding how to create a test class for a controller extension. I am clutching at straws when building the Test Class and now have 66% code coverage. Your help to adjust the below code will be much appreciated and help greatly in my understanding. The Visualforce page is very simple:
<apex:page standardController="Case"
extensions="Case_ListOppSplits_Controller" lightningStylesheets="true">
<apex:pageBlock >
<apex:pageBlockTable value="{!Opportunity_Splits}" var="oppSplit">
<apex:column value="{!oppSplit.Name}"/>
<apex:column value="{!oppSplit.Split_Loan_Amount__c}"/>
<apex:column value="{!oppSplit.Loan_Usage__c}"/>
<apex:column value="{!oppSplit.Loan_Purpose__c}"/>
<apex:column value="{!oppSplit.Rate_Type__c}"/>
<apex:column value="{!oppSplit.Repayment_Type__c}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>`
The controller extension is:
public class Case_ListOppSplits_Controller {
public Case myCase;
public Case_ListOppSplits_Controller(ApexPages.StandardController stdController){
this.myCase = (Case)stdController.getRecord();
}
public list<Opportunity_Split__c> getOpportunity_Splits(){
Case currentCase = [SELECT Id, Subject, Opportunity__c FROM Case WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
List<Opportunity_Split__c> OppSplits = [SELECT Id, Name, Opportunity__c, Loan_Purpose__c, Loan_Type__c, Loan_Usage__c, Rate_Type__c, Repayment_Type__c, Split_Loan_Amount__c FROM Opportunity_Split__c WHERE Opportunity__c =: currentCase.Opportunity__c];
return OppSplits;
}
}
Test Class:
@isTest
public class Case_ListOppSplits_Controller_Test {
static testMethod void testMethod1()
{
Case testCase = new Case();
testCase.Subject='Test Case';
testCase.Opportunity__c='0067F00000N8vSVQAZ';
testCase.RecordTypeId='0126D000000qSBcQAM'; //UA
testCase.Status='Assigned';
insert testCase;
Test.StartTest();
PageReference pageRef = new PageReference('https://omniwealth--dwr.my.salesforce.com/apex/Case_OpportunitySplits?id='+testCase.Id);
ApexPages.StandardController sc = new ApexPages.StandardController(testCase);
Case_ListOppSplits_Controller extn = new Case_ListOppSplits_Controller(sc);
List<Opportunity_Split__c> listOppSplits = extn.getOpportunity_Splits();
Test.StopTest();
}
}