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
Arijit Mandal 6Arijit Mandal 6 

Why Test methods are always static?

Best Answer chosen by Arijit Mandal 6
Medhya MahajanMedhya Mahajan
Hi Arijit,

Test Methods are static because you do not call the test methods explicitly when you run a class for execution. 

When you run your apex tests these methods needs to be executed whether they are called or not which is why we make them static so they can be run while the class excecutes.

 A static method doesn’t require an instance of the class in order to run. They’re created with every object instantiated from the class in which they’re declared.

Mark as solved if this helps.

Regards
Medhya Mahajan

All Answers

Medhya MahajanMedhya Mahajan
Hi Arijit,

Test Methods are static because you do not call the test methods explicitly when you run a class for execution. 

When you run your apex tests these methods needs to be executed whether they are called or not which is why we make them static so they can be run while the class excecutes.

 A static method doesn’t require an instance of the class in order to run. They’re created with every object instantiated from the class in which they’re declared.

Mark as solved if this helps.

Regards
Medhya Mahajan
This was selected as the best answer
Arijit Mandal 6Arijit Mandal 6
Thanks Medhya... 
Shashank SaireShashank Saire
So helpful. Thanks Medhya.