Note on using fake Ids: I was wrong!! --> standard objects Id prefixes don't change from org to org, but custom objects do, and I had completely forgotten this. This is a solution to get a fake Id dynamically, that won't fail when you move the test to a different org: /** * @description getFakeId * @summary Generates a record Id for an SObjectType without having to insert a record. * @param sobjType The Schema.SObjectType * @param startNumber * @return String value */ public static String getFakeId(Schema.SObjectType sobjType, Integer startNumber) { String result = String.valueOf(startNumber++); return sobjType.getDescribe().getKeyPrefix() + '0'.repeat(12 - result.length()) + result; } You can also check salesforce.stackexchange.com/questions/21137/creating-unit-tests-without-interacting-with-the-database-creating-fake-ids
Glad to see something about fake IDs, but you seemed to miss covering mocking methods and classes. You stuck with static methods being tested, which, as you know, cannot be mocked. It would be good to do a session focused on a unit testing mocking framework.
I like to see you keep your test classes private. I always recommend this since tests should never interfere with production code.
Note on using fake Ids: I was wrong!! --> standard objects Id prefixes don't change from org to org, but custom objects do, and I had completely forgotten this. This is a solution to get a fake Id dynamically, that won't fail when you move the test to a different org:
/**
* @description getFakeId
* @summary Generates a record Id for an SObjectType without having to insert a record.
* @param sobjType The Schema.SObjectType
* @param startNumber
* @return String value
*/
public static String getFakeId(Schema.SObjectType sobjType, Integer startNumber) {
String result = String.valueOf(startNumber++);
return sobjType.getDescribe().getKeyPrefix() + '0'.repeat(12 - result.length()) + result;
}
You can also check salesforce.stackexchange.com/questions/21137/creating-unit-tests-without-interacting-with-the-database-creating-fake-ids
Live starts at 14:59. You're welcome.
Glad to see something about fake IDs, but you seemed to miss covering mocking methods and classes. You stuck with static methods being tested, which, as you know, cannot be mocked. It would be good to do a session focused on a unit testing mocking framework.
Yes!! That's my plan, when my other priorities let me :)
Let's go :)