codeLive: Writing Effective Apex Tests

Поділитися
Вставка
  • Опубліковано 15 вер 2024

КОМЕНТАРІ • 6

  • @PieterJacob
    @PieterJacob 3 місяці тому

    I like to see you keep your test classes private. I always recommend this since tests should never interfere with production code.

  • @AlbaRivasSalesforce
    @AlbaRivasSalesforce 5 місяців тому +3

    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

  • @philw4740
    @philw4740 5 місяців тому +1

    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.

  •  5 місяців тому +3

    Live starts at 14:59. You're welcome.

  • @petargechev1852
    @petargechev1852 5 місяців тому

    Let's go :)