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
benwrigleybenwrigley 

Test methods or test classes

Hi All,

 

It seems that SalesForce recommends creating a separate test class to hold the test methods for a normal call. Is this considered best practise? How can you unit test private methods?

 

I've seen people storing a test methods inside the primary class so that they are bundled together. Presumably this will allow access to the private methods and keeps things looking tidier. However, I've noticed that doing this, my mock objects don't get torn down again afterwards. Would that be right?

 

TIA

 

 

ShwetaSShwetaS

Hi,

 

As such there is no standard as to how you should write the test methods. It's really an individuals preference. For small pieces of code some people put the test method within the class, for simplicity. For large pieces of code it's best to have a separate class for readability. Also SF has a limit of 100,000 characters for an APEX class, so in order to avoid hitting this limit its a good practice to write test method in a separate class.


Shweta
Salesforce Developer Support

If my answer solved your question, please mark it solved so I can help as many community members as possible!