You need to sign in to do that
Don't have an account?
JoshTonks
Im trying to write a test class
Im trying to write a test class for the below code. Ive written test classes before for things but for the life of me I cannot figure out how to get this to work with it. I feel like im missing something obvious. My apex class is below. The public list is passing the rest isnt.
public with sharing class CAengineerInvoices { List<Service_Booking__c> CAengineerInvoices; Service_Booking__c NetTotal; Service_Booking__c GrossTotal; public List <Service_Booking__c> getCAengineerInvoices(){ CAengineerInvoices = [SELECT Eng_Qty__c, CA_Gross_Amount__c, CA_Gross_Total_VF__c, Description_Of_Work__c, Description_of_Additional_work__c,Service_Company_Name__c, Company_Name__c, Registration_s__c, Name, Booking_Date_Time__c, CA_Eng_Net_Price__c, KM_Over__c, CA_Tax_Amount__c,Gross_Amount__c, Booking_Date_Time_Fomrula__c FROM Service_Booking__c WHERE Booking_Confirmed__c = True AND Service_Company__c = :ApexPages.currentPage().getParameters().get('Id')]; return CAengineerInvoices; } public Service_Booking__c getNetTotal() { NetTotal = new Service_Booking__c(CA_Eng_Net_Price__c = 0); for(Service_Booking__c CAI : getCAengineerInvoices()){ NetTotal.CA_Eng_Net_Price__c += CAI.CA_Eng_Net_Price__c; } return NetTotal; } public Service_Booking__c getGrossTotal() { GrossTotal = new Service_Booking__c(CA_Gross_Total_VF__c = 0); for(Service_Booking__c GT : getCAengineerInvoices()){ GrossTotal.CA_Gross_Total_VF__c += GT.CA_Gross_Total_VF__c; } return GrossTotal; } public Account getAccount() { return [SELECT Id, Name FROM Account WHERE Id = :ApexPages.currentPage().getParameters().get('Id')]; } }
You could either add a public access modifier to the definition
and then set it directly, or add a (testVisible only) private setter in there...
which would let you set that list from a test method and then evaluate it's output... sort of like so:
(all this code was hand crafted in here, so is probably full of syntax errors!)
Hope that helps?
All Answers
You could either add a public access modifier to the definition
and then set it directly, or add a (testVisible only) private setter in there...
which would let you set that list from a test method and then evaluate it's output... sort of like so:
(all this code was hand crafted in here, so is probably full of syntax errors!)
Hope that helps?
CAengineerInvoices cae = new CAengineerInvoices();
either fill in the fields and do
cae.insert()
or
CAengineerInvoices cae = new CAengineerInvoices({
field: value,
etc....
});
cae.insert();
then select your new cae invoice and perform an assertEqual
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_error_handling.htm