You need to sign in to do that
Don't have an account?
Newbie to unit testing
Hi
I am new to test classes. I have made controller which contain only querries. I need help to make a test class of it.
what should be the approach?
///////////////////////controller///////////////////////////////////////
public with sharing class Bcaformatcontroller{
public String workstations { get; set; }
public date today{get;set;}
public String offerID = ApexPages.currentPage().getParameters().get('Id');
public List <RealSteer__LeaseOffer__c> records {get;set;}
public List<Contact> licenseeCon {get;set;}
public List<AccountContactRole> licenseeConID {get;set;}
public List<AccountContactRole> licensorConID {get;set;}
public List<Contact> licensorCon {get;set;}
public List<Services__c> charge{get; set;}
public List<Services__c> chargeParking{get; set;}
public String pdfURL{get;set;}
public Bcaformatcontroller(){
today = System.today();
records = [Select r.Deposit_ask_for__c, r.Start_Date__c, r.RealSteer__Property__r.Name,RealSteer__Property__r.RealSteer__Street__c,RealSteer__Property__r.RealSteer__City__c,
RealSteer__Property__r.RealSteer__State__c,RealSteer__Property__r.RealSteer__Country__c, Offer_Through__c, RealSteer__Property__r.Account__c,
r.RealSteer__Property__c, r.Name, r.Id, r.End_Date1__c, r.Duration__c,Company_Name__r.Name,r.RealSteer__Property__r.Total_L_Shaped__c, r.RealSteer__Property__r.Total_Linear__c,
r.Company_Name__c, Broker_Name__c,Company_Name__r.BillingCountry,Company_Name__r.BillingPostalCode,
Company_Name__r.BillingState,Company_Name__r.BillingCity,Company_Name__r.BillingStreet ,r.Lock_In_Period__c, r.Notice_Period__c
From RealSteer__LeaseOffer__c r where id = :offerID];
licenseeConID = [SELECT ContactId FROM AccountContactRole WHERE (IsPrimary =: true AND AccountId =: records[0].Company_Name__c)];
licenseeCon = [Select LastName,Phone,Fax, FirstName, Salutation From contact where id =: licenseeConID[0].ContactId ];
licensorConID = [SELECT ContactId FROM AccountContactRole WHERE (IsPrimary =: true AND AccountId =: records[0].RealSteer__Property__r.Account__c)];
licensorCon = [Select LastName,Phone,Fax, FirstName, Salutation From contact where id =: licensorConID[0].ContactId ];
charge = [Select Charges_Per_Hour__c from Services__c where (Business_Center_Name__c = :records[0].Company_Name__c AND RecordTypeid in(select id from recordtype where name = : 'Internet Services'))];
chargeParking = [Select Parking_Rate__c from Services__c where (Business_Center_Name__c = :records[0].Company_Name__c AND RecordTypeid in(select id from recordtype where name = : 'Parking'))];
}
}
Thanks
Ishan Sharma
Ishan - Here is a rough template:
1. Setup test data for the org for all the queried objects
2. Set current visualforce page using Test.system.currentpageReference
3. Set up offerid parameter for the page
4. Instantiate object of controller class
5. Assert record counts and expected positive/negative test cases
All Answers
Ishan - Here is a rough template:
1. Setup test data for the org for all the queried objects
2. Set current visualforce page using Test.system.currentpageReference
3. Set up offerid parameter for the page
4. Instantiate object of controller class
5. Assert record counts and expected positive/negative test cases
Hi Ishan,
Basically your test class should
Regards,
Ashish
Thanks to both of you . This was helpful. I am done with my test class.
Hi Ishan,
Great to know, you are welcome!
Regards,
Ashish