Apex debugger with Callout mocks

Issue #1583 resolved
Xander Victory created an issue

This is likely technically a Salesforce bug, but when debugging a Test which uses a HTTP Callout Mock, I can’t step through the Mock class' code, seemingly because the log is missing a METHOD_ENTRY or CODE_UNIT_STARTED entry.

It does seem to have VARIABLE_SCOPE_BEGIN though

12:33:26.98 (263559978)|STATEMENT_EXECUTE|[154]
12:33:26.98 (263573421)|VARIABLE_SCOPE_BEGIN|[154]|http|System.Http|true|false
12:33:26.98 (263652764)|VARIABLE_ASSIGNMENT|[154]|http|"System.Http[]"|0x41f08862
12:33:26.98 (263661383)|STATEMENT_EXECUTE|[155]
12:33:26.98 (263674356)|SYSTEM_METHOD_ENTRY|[155]|System.Http.send(ANY)
12:33:26.98 (263874740)|HEAP_ALLOCATE|[155]|Bytes:4
12:33:26.98 (263894912)|HEAP_ALLOCATE|[155]|Bytes:78
12:33:26.98 (263903379)|VARIABLE_SCOPE_BEGIN|[4]|this|ttMYOBMockApi|true|false
12:33:26.98 (263922597)|VARIABLE_ASSIGNMENT|[4]|this|{}|0x6ea6c486
12:33:26.98 (263933173)|VARIABLE_SCOPE_BEGIN|[4]|req|System.HttpRequest|true|false
12:33:26.98 (264014390)|VARIABLE_ASSIGNMENT|[4]|req|"System.HttpRequest[Endpoint=callout:endpoint/1234/Contact/Customer/?$filter=UID%20eq%20guid'no_display_id', Method=GET]"|0x3129a1d2
12:33:26.98 (264042309)|STATEMENT_EXECUTE|[5]
12:33:26.98 (264044391)|STATEMENT_EXECUTE|[6]
12:33:26.98 (264051910)|SYSTEM_METHOD_ENTRY|[6]|ttMYOB_Settings__c.getOrgDefaults()
12:33:26.98 (264277172)|HEAP_ALLOCATE|[6]|Bytes:72
12:33:26.98 (264288850)|SYSTEM_METHOD_EXIT|[6]|ttMYOB_Settings__c.getOrgDefaults()
12:33:26.98 (264295835)|VARIABLE_SCOPE_BEGIN|[6]|myobSettings|ttMYOB_Settings__c|true|false
12:33:26.98 (264345462)|VARIABLE_ASSIGNMENT|[6]|myobSettings|{"Id":"a0B9D000001BO0b",<snip>}|0x6567d508
12:33:26.98 (264358329)|STATEMENT_EXECUTE|[8]
12:33:26.98 (264361839)|HEAP_ALLOCATE|[8]|Bytes:18
12:33:26.98 (264377272)|SYSTEM_METHOD_ENTRY|[8]|System.HttpRequest.getEndpoint()
12:33:26.98 (264406934)|HEAP_ALLOCATE|[8]|Bytes:78
12:33:26.98 (264414291)|SYSTEM_METHOD_EXIT|[8]|System.HttpRequest.getEndpoint()
12:33:26.98 (264422862)|HEAP_ALLOCATE|[8]|Bytes:96
12:33:26.98 (264435997)|SYSTEM_METHOD_ENTRY|[8]|System.debug(ANY)
12:33:26.98 (264441974)|USER_DEBUG|[8]|DEBUG|request endpoint: callout:endpoint/1234/Contact/Customer/?$filter=UID%20eq%20guid'no_display_id'
request endpoint: callout:endpoint/1234/Contact/Customer/?$filter=UID%20eq%20guid'no_display_id'
12:33:26.98 (264449005)|SYSTEM_METHOD_EXIT|[8]|System.debug(ANY)
12:33:26.98 (264453076)|STATEMENT_EXECUTE|[11]
12:33:26.98 (264465270)|HEAP_ALLOCATE|[11]|Bytes:13
12:33:26.98 (264471325)|VARIABLE_SCOPE_BEGIN|[11]|endpointBase|String|false|false
12:33:26.98 (264483643)|VARIABLE_ASSIGNMENT|[11]|endpointBase|"endpoint/1234"
12:33:26.98 (264490917)|STATEMENT_EXECUTE|[12]
12:33:26.98 (264498578)|SYSTEM_METHOD_ENTRY|[12]|System.HttpRequest.getEndpoint()
12:33:26.98 (264509670)|HEAP_ALLOCATE|[12]|Bytes:78
12:33:26.98 (264515193)|SYSTEM_METHOD_EXIT|[12]|System.HttpRequest.getEndpoint()
12:33:26.98 (264522114)|HEAP_ALLOCATE|[12]|Bytes:21
12:33:26.98 (264541230)|SYSTEM_METHOD_ENTRY|[12]|String.startsWith(String)
12:33:26.98 (264555056)|SYSTEM_METHOD_EXIT|[12]|String.startsWith(String)
12:33:26.98 (264561085)|HEAP_ALLOCATE|[12]|Bytes:19
12:33:26.98 (264570786)|SYSTEM_METHOD_ENTRY|[12]|System.assert(Boolean, ANY)

Beginning at line 8 of the log (where it refers to line 4), its definitely running my Mock class:

Comments (4)

  1. Scott Wells repo owner

    This finally popped up on my queue today again (sorry it took so long!). So it looks like if you set the log levels sufficiently high for the CALLOUT log category, you get CALLOUT_REQUEST and CALLOUT_RESPONSE events bounding the actual callout, and within that there's some information about the mock being used. I'll investigate whether I can use that information to allow the debugger to push/pop a stack frame accordingly. If so, I'll likely change the default debugging log level presets to raise the CALLOUT level so that it's captured automatically.

  2. Scott Wells repo owner

    Fix committed for inclusion in next week's build:

    Issue_1583.png

    While I was in that area, I also fixed a few issues with debugging Apex stubs to ensure that the debugger properly steps into and out of those properly. The issues there were primarily cosmetic, though, and the debugger actually did structure and execute the stack frames properly already.

  3. Log in to comment