You need to sign in to do that
Don't have an account?
laytro1978
Help on testing script
Hi,
Can someone please give me a hand on the test method for this piece of APEX.
Any help would be much appreciated.
I have made a start in red below.
Thanks
Ross
public class TimeEntry { public List<Time_Slot__c> slots {get; set;} public TimeEntry(){ slots = new List<Time_Slot__c>(); slots.add(new Time_Slot__c()); } public void addrow() { slots.add(new Time_Slot__c()); } public void removerow(){ Integer i = slots.size(); slots.remove(i-1); } public PageReference save() { insert slots; PageReference home = new PageReference('/a00/o'); home.setRedirect(true); return home; } public static testMethod void TimeEntry() { //setup test data Time_Slot__c T = new Time_Slot__c(); insert t; //test main controller action List<Time_Slot__c> slots; } }
Should look something more like this. Instantiate the class, excercise the methods, and make assertions.
public static testMethod void TimeEntryTest()
{
TimeEntry t = new TimeEntry();
System.assertEquals(t.slots.size(),0);
t.addRow();
System.assertEquals(t.slots.size(),1);
t.removeRow();
System.assertEquals(t.slots.size(),0);
t.addRow();
Pagereference p = t.save();
}
All Answers
Should look something more like this. Instantiate the class, excercise the methods, and make assertions.
public static testMethod void TimeEntryTest()
{
TimeEntry t = new TimeEntry();
System.assertEquals(t.slots.size(),0);
t.addRow();
System.assertEquals(t.slots.size(),1);
t.removeRow();
System.assertEquals(t.slots.size(),0);
t.addRow();
Pagereference p = t.save();
}
Thanks for this I understand what I need to do.
Cheers
R