Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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

static testMethod void myTest() {
//
}

and

@isTest
static void myTest() {
//
}

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

share|improve this question

1 Answer 1

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 Salesforce.com 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

 
discard

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.