function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
birdofpreybirdofprey 

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();

 

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

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

abhishektandon2abhishektandon2

What exactly is the issue?

vishal@forcevishal@force

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 :

@isTest
	Private class testCoverage
	{
		private static void testMethod test1()
		{
			ItemsApprove Itemcontroller = new ItemsApprove();
			
			Itemcontroller.getFFData();
			Itemcontroller.getProcessInstance();
		}
	}

 


Navatar_DbSupNavatar_DbSup

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. 

This was selected as the best answer