5

I love the option of running test methods from VSCode by clicking on Run Test link that appears below the @isTest annotation. This works well but when a test method fails, I go ahead and add a System.debug() statement to troubleshoot where it is failing. But it never prints the debug statements from the test method or actual method.

I tried running sfdx force:apex:test:run --loglevel trace but still it just prints the result and doesn't print the debug statements.

Can someone help me on this?

2 Answers 2

4

You can use:

sfdx force:apex:log:get

to get the last log file or use:

sfdx force:apex:log:tail --color

to stream the log file output to your console. (See e.g. Streaming Debug Logs to your console.)

3
  • Ok. I thought we can fiddle with arguments passed to the command sfdx force:apex:test:run and get debug statements printed along with pass or fail result. That would have been so handy.
    – javanoob
    Jun 13, 2019 at 20:29
  • @javanoob Not AFAIK. But the tail option is pretty nice.
    – Keith C
    Jun 13, 2019 at 20:32
  • You are right. This workaround is lot better than going into the developer console for logs.
    – javanoob
    Jun 13, 2019 at 20:41
2

Thanks for this! Here is what we came up with to show only user DEBUG in the stream (similar to the filtered option in IntelliJ/Webstorm with Illuminated Cloud):

sfdx force:apex:log:tail --color | grep --line-buffered "USER_DEBUG"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .