Testing has always been an integral part of the development cycle on the Force.com platform – one well-known fact is that Apex Code must have at least 75% test coverage (and ideally more!) before it is pushed into production; another, slightly less well-known, is that we run ALL eight million plus of those customer tests on EVERY release of the Force.com platform.

Winter ’12 brings a number of enhancements to testing on Force.com. Perhaps most interesting for ISVs writing apps for the AppExchange is the new @IsTest(OnInstall=true) annotation. As the syntax suggests, you can now specify whether or not individual tests are run during the installation of a managed or unmanaged package. From Winter ’12 on, only methods and classes annotated with @IsTest(OnInstall=true) will be executed at install-time. Note that packages created prior to the Winter ’12 release aren’t affected by this annotation and all their tests will still be run during installation.

Another enhancement is that classes annotated with @IsTest no longer have to be private. You can now create public test classes – very useful for factoring out common test code that you want to call from a number of test classes. If you’re thinking of using public test classes to sneak around limits, beware – methods of a public test class can only be called from a running test, that is, a test method or code invoked by a test method, and can’t be called by a non-test request.

Finally, a new API for asynchronous testing enters public beta in Winter ’12. ApexTestQueueItem allows you to manage queued Apex test jobs, while ApexTestResult represents the result of an Apex test execution. These two new objects are accessible from Apex Code as well as the SOAP and REST APIs, allowing scope for easy integration with continuous integration testing environments, and there is a simple example in the documentation that shows how to find and queue all classes ending in ‘Test’.

So, whether you consider testing a necessary evil or backbone of the development process, Winter ’12 has something for you – check out the release notes [PDF] and Force.com Apex Code Developer’s Guide for full details on all of the above features and much, much more.

Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS