+ Start a Discussion
code developercode developer 

Regarding Unit Test classes

Hi,

I am new apex and visualforce. I have simple question. Why we write "static" keyword for test methods.

Thanks in advance.

Best Answer chosen by Admin (Salesforce Developers) 
harsha__charsha__c

Hi, 

 

Like the other methods, we are not calling the test method by the class instance.

 

Some standard salesforce mechanism invokes the test method of a perticular class.

 

You might be knowing that the static methods can be directly accessed by the class name itself. They doesn't need  to create an instance of it's class to access.

 

So test methods are given " static " keyword in order the salesforce test execution mechanism can invoke a test method directly by just it's class name.

All Answers

harsha__charsha__c

Hi, 

 

Like the other methods, we are not calling the test method by the class instance.

 

Some standard salesforce mechanism invokes the test method of a perticular class.

 

You might be knowing that the static methods can be directly accessed by the class name itself. They doesn't need  to create an instance of it's class to access.

 

So test methods are given " static " keyword in order the salesforce test execution mechanism can invoke a test method directly by just it's class name.

This was selected as the best answer
code developercode developer

Thank you very much Harsha!!!