You need to sign in to do that
Don't have an account?
birdofprey
Need help writing Test Code
Someone please help me in my first attempt at a test class.
I have a apex class that only contain two functions that only returns data not set.
global class ItemsApprove { private final string UserID = UserInfo.getUserId(); private List<ProcessInstance> ProcessInstanceID {get; set;} public String getUserID() {return UserID;} public ItemsApprove(){} public List<Form__c> getFSData() { Set<ID> getID = new Set<Id>(); . . . return FSData; } public List<ProcessInstance> getProcessInstance() { ... return ProcessInstanceID; } }
and this is my poor attempt on the test class, which doesn't save to the server.
PageReference pageRef2 = Page.success; Test.setCurrentPage(pageRef2); ItemsToApprove Itemcontroller = new ItemsApprove (); Itemcontroller = new ItemsApprove(); Itemcontroller.getFFData(); Itemcontroller.getProcessInstance();
Hi,
Try the below code with test method of your class:
global class ItemsApprove {
private final string UserID = UserInfo.getUserId();
private List<ProcessInstance> ProcessInstanceID {get; set;}
public String getUserID() {return UserID;}
public ItemsApprove(){}
public List<Form__c> getFSData() {
Set<ID> getID = new Set<Id>();
return null;
}
public List<ProcessInstance> getProcessInstance() {
return ProcessInstanceID;
}
public static testMethod void classTestMethod()
{
ItemsApprove i=new ItemsApprove();
i.getUserID();
i.getProcessInstance();
i.getFSData();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
All Answers
What exactly is the issue?
while saving your class to the server, what error are you getting?
One thing I found is this :
ItemsToApprove ItemController = new ItemsApprove();
It should have been :
ItemsApprove ItemController = new ItemsApprove();
Try this code and let me know if it helps :
Hi,
Try the below code with test method of your class:
global class ItemsApprove {
private final string UserID = UserInfo.getUserId();
private List<ProcessInstance> ProcessInstanceID {get; set;}
public String getUserID() {return UserID;}
public ItemsApprove(){}
public List<Form__c> getFSData() {
Set<ID> getID = new Set<Id>();
return null;
}
public List<ProcessInstance> getProcessInstance() {
return ProcessInstanceID;
}
public static testMethod void classTestMethod()
{
ItemsApprove i=new ItemsApprove();
i.getUserID();
i.getProcessInstance();
i.getFSData();
}
}
Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.