1

I'm currently updating a lot of my unit tests to get a healthy average above 75% for some wiggle room. The controller I am currently testing on has a SOQL query within the method I am testing.

try {
     List<PreferredConstituentInfos__x> pis = [select 
         consType__c,
         constituent_id__c,
         title__c,
         first_name__c,
         middle_name__c,
         ........                  
         phoneType__c
     from
         PreferredConstituentInfos__x
     where
         constituent_id__c = :currCase.ConstituentID__c];

Within my unit test I am trying to force fake values into this query when the test runs. That way it will go within the next if statement:

if (pis.size() == 1) {

Does this require a mock method within the test class? Or is there a way to inject the values into the controller during the test run? I'm pretty new to test classes and I inherited this code I'm trying to test. So trying to see the whole picture and write unit test from scratch is challenging.

1 Answer 1

1

Since this is the equivalent of a call-out, a mock would seem to be appropriate since you're going through the Salesforce Connect adaptor. For that reason, this could also be considered an asynchronous operation.

Using a CSV file, you'd need to insert the data, so that wouldn't seem to help unless your object was writable (you didn't say). I'd recommend mocking it as going through a connector.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .