Activity Forums Salesforce® Discussions Why test method always static in Salesforce?

  • Adarsh

    Member
    February 7, 2018 at 6:01 AM

    Hi Uday,

    Test Methods are static in Salesforce 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 executes.

    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.

    Hope it helps 🙂

Log In to reply.

Popular Salesforce Blogs

How Salesforce Boosted the Reach of MrBeast’s $1M Puzzle

Blog in

Salesforce partnered with YouTuber MrBeast for a groundbreaking Super Bowl campaign that turned a traditional ad into an interactive $1 million puzzle hunt, massively amplifying…

Popular Salesforce Videos