I have the following code in a test class
parent__c parent = new parent__c();
insert parent;
child__c child = new child__c();
child.parent__c = parent.Id;
insert child;
In the DataBase, the relationship from the parent to the child is called child__r and it is populated for many records.
If I try
System.debug('@@@@@ --> '+[SELECT Id, parent__c FROM child__c]);
I get the child Id and parent Id correctly, but if I try
System.debug('@@@@@ --> '+[SELECT Id, (SELECT Id FROM child__r) FROM parent__c]);
Only the parent is returned, in other words, the relationship is not populated and
System.debug('@@@@@ --> ' + parent.child__r);
is empty.
In the tested class, an If statement has in the condition "!child__r.isEmpty()", how can I populate the relationship?
P.S. I cannot use isRunningTest()
since then I could not enter in the ELSE statement.