5

I just recently learned from the Apex Developer Guide documentation on the IsTest Annotation:

The testMethod keyword is now deprecated. Use the @isTest annotation on classes and methods instead.

Are there API Versions where use of this keyword will cause a compile fail? If not, do we know if/when that is coming?

2 Answers 2

2

The testMethod keyword is now deprecated. Use the @isTest annotation on classes and methods instead.

I've been telling people not to use this for ages; @isTest is not just a testMethod replacement, it allows us to specify things like parallel testing boundaries and database isolation.

Are there API Versions where use of this keyword will cause a compile fail?

Not at this time. There's no specific announcement at this time, so it's probably at least a year out (v45.0 or later). Besides, if they tie it to a version, then it'll be like database isolation and unit test method isolation (v27.0/v28.0). Older classes will work for some time (probably at least 3-5 years), but newer classes will compile-fail if you specify a newer version. Note that the actual dates are just examples, since we don't have a formal time line.

If not, do we know if/when that is coming?

It may never come. The bulk keyword, introduced in the earliest days of Apex Code, is still supported, despite being vestigial for about a decade now. Most likely, given they've marked it as deprecated, it'll be version-locked at some point, but I doubt it will ever fully go away, as long as people are using it, which may well take a decade or longer.

2
  • Does that mean you can do IsTest(isParallel=true) at the method level? So @IsTest(isParallel=true) static testA(){} ?
    – EricSSH
    Jan 31, 2018 at 21:31
  • @EricSSH I hadn't actually tried, but no, you can't specify parallel at the method level. I wonder if this is something they'll support later?
    – sfdcfox
    Jan 31, 2018 at 21:39
1

I haven't seen anywhere in documentation and Google search that the deprecation will cause/have caused problems.

Personally I don't think Salesforce will cause a compile fail specifically for this keyword, as this would be existing in code in all instances and it would've been a nightmare for companies to clean up and change. Release documentation would've been pretty clear of any deadline.

I also created a few test classes in recently unwittingly still including testMethod (API ver 41), and was able to deploy them in production.

Best I think would be to create a Salesforce case and ask them.

1
  • I don't think they would cause compile failures before a specific version. Also the new release is 42.0 so I would be surprised to see it happen in any version below that.
    – Adrian Larson
    Jan 31, 2018 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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