codeLive: Writing Effective Apex Tests

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 พ.ย. 2024

ความคิดเห็น • 6

  • @PieterJacob
    @PieterJacob 4 หลายเดือนก่อน

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

  • @AlbaRivasSalesforce
    @AlbaRivasSalesforce 7 หลายเดือนก่อน +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

  •  7 หลายเดือนก่อน +3

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

  • @philw4740
    @philw4740 7 หลายเดือนก่อน +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.

    • @AlbaRivasSalesforce
      @AlbaRivasSalesforce 2 หลายเดือนก่อน

      Yes!! That's my plan, when my other priorities let me :)

  • @petargechev1852
    @petargechev1852 7 หลายเดือนก่อน

    Let's go :)