2

I was having a discussion on the usage of the testMethod modifier versus the @IsTest annotation. I have my opinion, but I'll try not to bias the results one way or another by expressing it here.

If you were introducing someone to Apex, which would you use and why?

I started a twitter poll as it seemed like an easier way to gather the results. https://twitter.com/FishOfPrey/status/854517221065752576

2
  • testMethod - cleaner and easier to read IMHO. Not sure it really matters though so it comes down to preference? – Eric Apr 19 '17 at 3:43
  • 1
    I like to use @IsTest because I think that when we read annotations, we understand faster that this is not code. Also, when I was using the testMethod modifier, I never knew where I had to add it. Because its surrounded by other method modifiers. – Martin Lezer Apr 19 '17 at 7:27
8

Personally, I'd go with @isTest based on Jason Clark's answer in 2014 on your question from 2012.

From that answer:

Why? If I need to disable a test, I can just comment out the @isTest line like so:

//@isTest
static void TestSomething() { ... }

Beyond that, the testMethod modifier appears to be a one-off feature of Apex. By that, I mean that other programming features specific to Apex tend not to use keywords baked into the class definition or method signature.

The only other example of a class/method modifier that I can think of is webservice. Nearly everything else uses annotations. I think I'd prefer using @isTest for test methods just for sake of being consistent.

1
  • Never thought about this.....Good reason to use the annotation... – Eric Apr 24 '17 at 15:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .