Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When working on unit tests in apex, what's the difference between the following code snippets?

static testMethod void myTest() {


static void myTest() {

Are they just different approaches to method definition or is there more to it?

share|improve this question
up vote 4 down vote accepted

Based on the @IsTest documentation they are equivalent, and no benefit or prefered syntax is mentioned.

I suspect the testMethod keyword was first, and that they needed an alternative that could take the SeeAllData parameter when hiding your actual data from tests by default.

For Apex code saved using API version 24.0 and later, use the isTest(SeeAllData=true) annotation to grant test classes and individual test methods access to all data in the organization, including pre-existing data that the test didn’t create.

So I expect the isTest annotation didn't exist before API 24.0.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.