While recently working on a large project where unit test executions would run upwards of 2 hours, we realized we could get a performance gain by avoiding touching the database (e.g. SOQL and DML) during our tests.
So if we wanted to work with Accounts, we might have some code like this:
public class AccountDao
{
@testVisible private static List<Account> mockResultList = null; // Does NOT support multiple queries of same SObject in same test!
public static List<Account> getList()
{
if (mockResultList != null) { System.debug (LoggingLevel.WARN, '!!!!! Unit test uses Account mockResultList: ' + mockResultList); }
List<Account> accountList = (Test.isRunningTest() && (mockResultList != null))
? mockResultList
: [SELECT id, name FROM Account];
return accountList;
}
}
}
... where we could feed the expected result into mockResultList before testing the code which would execute AccountDao.getList().
This works fine for our purposes.
But now I am trying to do the same for an ApexClass query.
If I have some Apex class (e.g. a class named "MyClass"), is it possible to somehow add some representation of this to a List<ApexClass>
?