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 
         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.


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.