Sunday, 10 April 2016

GET READY FOR CHANGES TO APEX TESTING - Spring'16 Release



The Salesforce Spring'16 released with a long list of changes. As a developer, the changes that most excite me are generally those that are covered in the Development and Deployment categories of the Salesforce release notes.


Test Suites for Apex Test Classes


Salesforce has now added the option Suite to group unit test classes into test suites.you have test classes which you run every time while you preparing for deployment. Now, with this new feature, you can create test suite which contains those set of classes. Also, you can create or modify test suites that contain up to 200 test classes using the Developer console.

To create a Test Suite using Developer console : Select Test | New Suite.




Enter a name for your Test Suite.



To choose which classes are in a test suite, select Test | Suite Manager | Your Test Suite | Edit Suite.



Once you select your test classes(it will we more than one also), click on save button. After this to run your test class which you have selected, click on Test | New Suite Run.



Select the Test Suite you want to run and then click on your right corner button "Run Suite".



After clicking on Run Suite, you can see you result here:


Now you have created the test suite and executed your test classes. Isn't that easy..!!


Set and Modify CreatedDate field of the Tests Records


There is a new method has been introduced System.Test.setCreatedDate. You can change your records created date in the test class. This method we can utilize to test the scenarios where we are using created dates of a record.

Here is the example of how to use this method.


1:  Account a = new Account(name='myAccount');  
2:  insert a;  
3:  Test.setCreatedDate(a.Id, DateTime.newInstance(2012,12,12));  


6 comments: