function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Chris Walters 9Chris Walters 9 

debug statements in methods under unit tests not appearing

version 47.0

A curious thing: I've written a unit test that exercises a Task.afterInsert() method. I've added debug  -entering and -exiting statements to this method as well as the @isTest method, which creates and inserts a new Task.

Upon executing of the test I see my @isTest debug statements in my logs, the log shows the Id of the newly created Task, good so far ... but I do not see the debug statements from the method-under-test.
Why is that?

TIA,

Still-learning Chris
Agustin BAgustin B
Hi Chris, are you executing the tests as another user (runAs method)? Maybe thats why you only see a part of the debugs.

Check that please.
If it helps please like and mark as correct, it may help others.

if not do you have that part of the code to see more?
Chris Walters 9Chris Walters 9
That was a good guess. I am using a RunAs(thisUser)  so as to avoid the mixed-DML-in-testsetup issue. So I changed thisUser to me, but still only see the debug stmts from inside the @IsTest ... say, maybe I need to monkey with the Debug visibility settings....
Agustin BAgustin B
Hi Chris, you should then check your debug logs in order to ensure every user running has enable a log level for that moment. That is the only configuration regarding seeing logs.

If it helps please like and mark as correct so the question can be solved and people with the same issue can find this solution faster.
Good luck !
Chris Walters 9Chris Walters 9
Yes every user trying this has the same log-level enabled. It gets weirder - we can't figure out why debug statements (temporarily) embedded in the various methods of FooHandler don't print out when a Foo is created and inserted from within the @IsTest method but DO print when a Foo is created MANUALLY. Weirder still, we don't see this behaviour when we run Test_FootHandler.