You need to sign in to do that
Don't have an account?
Internal Partner
Use of custom setting data in a test class
Hi dear developers,
I am pretty confused about the use of custom settings in APEX test classes.
One of our developers, who unfortunately is not there anymore, wrote the following test data in a test method:
1. Name: CS_Config
Batch_Limit__c = 200,
Email_Address__c = test2@example.com
2. Name: Test_CS
Batch_Limit__c = 200,
Email_Address__c = test@example.com
And he had been using the name of the second Custom Setting record only for the test class. He had been using the first Custom Setting record for the APEX (non-test) batch job class.
Or, the second record is not needed and can be deleted?.
I am pretty confused about the use of custom settings in APEX test classes.
One of our developers, who unfortunately is not there anymore, wrote the following test data in a test method:
static testMethod void testMethodExample() { insert new CS_Example__c(Batch_Limit__c = 1, EmailAddress__c='test@example.com', Name = 'Test_CS');the test class works, but we don't understand why he created in addition to the test data within the test class, a new Custom Setting record with the name 'Test_CS". That means, he created two records on the Custom Setting CS_Example__c:
1. Name: CS_Config
Batch_Limit__c = 200,
Email_Address__c = test2@example.com
2. Name: Test_CS
Batch_Limit__c = 200,
Email_Address__c = test@example.com
And he had been using the name of the second Custom Setting record only for the test class. He had been using the first Custom Setting record for the APEX (non-test) batch job class.
Or, the second record is not needed and can be deleted?.
1. If you are test class is not contains see all data to true .. you cannt able to get any value from the custom settings so we need to insert data into the custom settings in test class
2. The above insert wll be rollbacked automatically
So, you mean the second physical record with name "Test_CS" can be deleted. This physical record is not necessary, right?.
The developer didn't use "see all data to true", so he inserted the test data the way I mentioned.
I guess you haven't understood my question :(.