You need to sign in to do that
Don't have an account?
Sylvie Serplet
Need help improving my Test Class
Hi All,
Need help improving my test class. Current coverage is 47%!
VF Page
Thanks in advance for your help.
Sylvie
Need help improving my test class. Current coverage is 47%!
VF Page
<apex:page controller="WorkCtr" lightningStylesheets="true" > <apex:slds /> <div class="slds-scope"> <apex:form > <apex:pageBlock > <apex:pageblocksection columns="2"> <apex:inputField value="{!wr.Date__c}"/> <apex:inputField value="{!wr.Name__c}"/> <apex:inputField value="{!wr.Comment__c}"/> </apex:pageblocksection> <apex:pageBlockSection columns="1"> <apex:pageBlockTable value="{!walist}" var="wa"> <apex:column headerValue="Percentage"> <apex:inputField value="{!wa.Percentage__c}"/> </apex:column> <apex:column headerValue="Assigned To"> <apex:inputField value="{!wa.Assigned_to__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> <apex:pageBlockButtons location="bottom"> <apex:commandButton value="Save" action="{!save}" /> <apex:commandButton value="Add Row" action="{!AddRow}" immediate="true"/> </apex:pageBlockButtons> </apex:pageBlock> </apex:form> </div> </apex:page>APEX Class
public with sharing class WorkCtr { public Workload__c wr{get;set;} public list <Work__c> walist{get;set;} public WorkCtr() { wr = new Workload__c(); walist = new List <Work__c>(); AddRow(); } public void AddRow(){ walist.add(new Work__c()); } public void save(){ if(wr.name__c !=null){ insert wr; List <Work__c> wal = new List <Work__c>(); for (Work__c w: walist) { w.Workload__c = wr.Id; w.Date__c = wr.Date__c; wal.add(w); } if(wal !=null) { insert wal; wr = new Workload__c(); walist = new List <Work__c>(); AddRow(); } } } }Test Class
@isTest private class WorkCtrTest { static testMethod void WorkCtrTest(){ Account acc = new Account(); acc.Name = 'Test Account'; insert acc ; Contact con = new Contact(); con.AccountId = acc.Id; con.LastName ='Test Name'; insert con; Contact con1 = new Contact(); con1.AccountId = acc.Id; con1.LastName ='Test Name'; insert con1; Workload__c wr = new Workload__c(); wr.Comment__c = 'This a test comment'; wr.Name__c = con.Id; wr.Date__c = System.Today(); insert wr; Work__c w = new Work__c(); w.Assigned_to__c = con.Id ; w.Date__c = wr.Date__c; w.Percentage__c = 50; w.Workload__c = wr.Id; insert w; Work__c w1 = new Work__c(); w1.Assigned_to__c = con1.Id ; w1.Date__c = wr.Date__c; w1.Percentage__c = 30; w1.Workload__c = wr.Id; insert w1; Test.StartTest(); WorkCtr obj = new WorkCtr(); obj.save(); Test.StopTest(); } }
Thanks in advance for your help.
Sylvie
All Answers
Thank you.
Sylvie
static testMethod void test() {
Test.startTest();
Account a= new Account();
a.A_Field_Picklist__c= '';
insert(a);
Account aObj = [SELECT A_Field_Picklist__c FROM Account WHERE Id=:a.Id];
aObj.A_Field_Picklist__c= 'A VALUE'; update aObj; System.assertEquals (....);
Test.stopTest(); }
Got the following error message:
Thank you so much for your help.
Sylvie