Custom Setting Creation in Apex Test Class
Please refer following approach to insert/update custom setting record in test class.
@isTest(SeeAllData=FALSE)
private class YouTestClass {
//Initialize custom settings to prevent test failures
// replace Dreamhouse_Settings__c = your custom setting name
private static Dreamhouse_Settings__c customSettingInstance;
static {
customSettingInstance = new Dreamhouse_Settings__c();
customSettingInstance.LIFX_Token__c = '';
upsert customSettingInstance;
}
static testMethod void yourTestMethod() {
Test.startTest();
//Your unit test here
Test.startTest();
}
}
@isTest(SeeAllData=FALSE)
private class YouTestClass {
//Initialize custom settings to prevent test failures
// replace Dreamhouse_Settings__c = your custom setting name
private static Dreamhouse_Settings__c customSettingInstance;
static {
customSettingInstance = new Dreamhouse_Settings__c();
customSettingInstance.LIFX_Token__c = '';
upsert customSettingInstance;
}
static testMethod void yourTestMethod() {
Test.startTest();
//Your unit test here
Test.startTest();
}
}
I hope this will help you.
Comments
Post a Comment