Created
April 23, 2015 06:28
-
-
Save hasanthaera/8f1528f41b2882a49ef0 to your computer and use it in GitHub Desktop.
Salesforce - @testsetup method : Spring 15 release
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@isTest | |
public class TestAccountCommon { | |
// setup test data for entire test methods in teh test class | |
@testSetup static void setup(){ | |
List<Account> lstAccounts = new List<Account>(); | |
for(integer i = 0;i<5; i++){ | |
lstAccounts.add( new Account( | |
FirstName = 'Test'+i, | |
LastName = 'user', | |
PersonEmail = 'test'+i+'@.com', | |
)); | |
} | |
insert lstAccounts; | |
} | |
// test method 1 which usues defined test data | |
@isTest static void Test_TestAccount_001() { | |
//get the setup data by SOQL | |
List<Account> updatedAccounts = [SELECT Id, isCheckDate__c FROM Account WHERE isCheck__c =: true]; | |
system.assertEquals( | |
5, | |
updatedAccounts.size(), | |
'Test_JobApplicationCommon_002: size of the retrieved accounts would be 5' | |
); | |
for(Account acc : updatedAccounts){ | |
acc.isCheck__c = true; | |
} | |
// update test data | |
update updatedAccounts; | |
for(Account acc : updatedAccounts){ | |
system.assertEquals( | |
Date.today(), | |
acc.isCheckDate__c, | |
'Test_JobApplicationCommon_002: The isCheckDate__c should be updated as todate' | |
); | |
} | |
} | |
// test method 2 which usues defined test data | |
@isTest static void Test_TestAccount_002() { | |
//get the setup data by SOQL | |
List<Account> updatedAccounts = [SELECT Id, isCheckDate__c FROM Account WHERE isCheck__c =: true]; | |
//new test method has initialized test data. | |
system.assertEquals( | |
5, | |
updatedAccounts.size(), | |
'Test_JobApplicationCommon_002: still the size of the retrieved accounts would be 5' | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment