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
Mike WaughMike Waugh 

Read a static file into Unit Test

Is there a way to read in a static file into a unit test?  


I am trying to unit test a large data set coming back in a JSON format from our webservice call and would like to load a sample text file for my unit tests.


The overall objective of the unit tests it to test the governor limits on batch inserting a large number of leads.





In test class put one if COndition



read text file here from static redource
write the txt value in json webservice response variable

this will surely work.  


if u like this post then put as a solution or ask me any question

Mike WaughMike Waugh

That is what I want to do.   Can you provide sample code of reading in a text file in Apex code?  I haven't been able to find a sample anywhere ...




We cant use Static Resource file in Apex Class.


You can  use document to upload the file.