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();
    }
}

I hope this will help you.

Comments

Popular posts from this blog

System.AsyncException: The Apex job named is already scheduled for execution.

Error : "Trigger must be associated with a job detail"

AJAX Toolkit Debug Shell

Salesforce Trace Log Query Using Apex

how to get object name from id / prefix value in salesforce

How to Query All the batch classes in your Salesforce Instance using APEX

Creating Salesforce Developer Account

Creating MAP from SOQL Query

Custom Pagination Without Controller (Apex)