+ Start a Discussion
bozotheclownbozotheclown 

Testing Help

I am having issues developing a test for the below code.  Any suggestions would be greatly appreciated.

Thanks in advance.



Public String GrabDate { get; set;}
Public String ComputedValSTR { get; set;}
Public Decimal ComputedVal { get; set;}

public List<aaa> getzzz() {
List<aaa> bbb = new List<aaa>();
AggregateResult[] ccc = [SELECT Date__c dt, SUM(Charges__c) FROM Cars__c GROUP BY Date__c ORDER BY Date__c asc];
for (AggregateResult xxx : ccc) {
GrabDate = string.valueOf(xxx.get('dt'));
ComputedValSTR = string.valueOf(xxx.get('expr0'));
ComputedVal = decimal.valueOf(ComputedValSTR);
bbb.add(new aaa(GrabDate, ComputedVal));
}
return bbb;
}


public class aaa {
public String DtValue { get; set; }
public Decimal ChargesVal { get; set; }

public aaa(String DtValue, Decimal ChargesVal) {
this.DtValue = DtValue;
this.ChargesVal = ChargesVal;
}
}
bob_buzzardbob_buzzard
How far have you got?  Can you post your current test code?
bozotheclownbozotheclown
Unfortunately, I am having trouble even getting started. I have been looking for sample code online - and am having issues getting anything to work. 
Vinita_SFDCVinita_SFDC
Hello,

In your test class, first you need to insert records to Cars__c and now on these inserted records you will query "SELECT Date__c dt, SUM(Charges__c) FROM Cars__c GROUP BY Date__c ORDER BY Date__c asc" and now with assert method you will check that the values obtained from select query are matching with the value provided while inserting the records.

Please refer following link for sample code on test class:

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_test.htm