Last active
September 12, 2019 19:59
-
-
Save latentfuss/589860c344edee03b06a161c642b1f13 to your computer and use it in GitHub Desktop.
Here is a design pattern for unit tests that I have implemented in Eclipse as a template. The testSetupData() method validates that your @testsetup data is working correctly, and helps to mitigate the risk of changes to workflow, process, and validation in your Org
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
/** | |
* This class contains unit tests for validating the behavior of Apex classes | |
* and triggers. | |
* | |
* Unit tests are class methods that verify whether a particular piece | |
* of code is working properly. Unit test methods take no arguments, | |
* commit no data to the database, and are flagged with the testMethod | |
* keyword in the method definition. | |
* | |
* All test methods in an organization are executed whenever Apex code is deployed | |
* to a production organization to confirm correctness, ensure code | |
* coverage, and prevent regressions. All Apex classes are | |
* required to have at least 75% code coverage in order to be deployed | |
* to a production organization. In addition, all triggers must have some code coverage. | |
* | |
* The @isTest class annotation indicates this class only contains test | |
* methods. Classes defined with the @isTest annotation do not count against | |
* the organization size limit for all Apex scripts. | |
* | |
* See the Apex Language Reference for more information about Testing and Code Coverage. | |
*/ | |
@isTest | |
private class ${class_name} { | |
//setup testClass variables here. For example: | |
//RecordType Ids | |
/*private static final Id Customer_RECORD_TYPE_ID = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Customer').getRecordTypeId();*/ | |
//A common Loop Counter for bulikification purposes | |
/*private static final integer MAX_LOOP_COUNTER = 200;*/ | |
@testSetup static void setupTestData(){ | |
//setup common test data here | |
${cursor} | |
} | |
static testMethod void testSetupData(){ | |
//use this method to validate that you have test data setup correctly | |
//this will protect you from changes to workflow, process, and validation that break your test code! | |
} | |
static testMethod void myUnitTest() { | |
// TO DO: implement unit test AFTER you have your test data all setup and verified as OK | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment