5

I am running Apex Tests and I need to see the debug value So I have used debug statements similar to below one:

System.debug(Logginglevel.ERROR , ' ::::::: My Debug :::::::::::::') ;

Still I am unable to see the messages in debug log b/c of max debug log size issue.

I am not sure why the levels are not changed in the above debug log.

enter image description here

9

Generally speaking, you can control the logging level using the TraceFlags.

TraceFlags have overriding authority over all other tracing methods. See Summer '15 Release notes - Receive Debug Logs Predictably.

As per Does the Summer ’15 release remove the ability to set test logging levels with the DebuggingHeader?, the current modifications seem a bit off to me, but they can be made to work.

So long story short, use the Developer Console Debug > Change Log Levels option to set your user level trace flags. You can also set specific trace flags for apex classes and triggers. These will be applied when capturing asynchronous test results.

enter image description here


If you want to go further, you can still exert control of the logging levels through other means. One option is to not have no active TraceFlags set when running the tests. This also requires having Developer Console closed, as it will set active TraceFlags when opened.

You can perform a synchronous test run using the Apex API and set a specific logging levels in the DebuggingHeader. If your interested in this approach I've made a tool that allows you to call this method for selected test classes or methods with defined logging levels.

enter image description here

  • I have changed going through developer console -> debug - > but it does not reflect anything regardless the change I made as you shown above and I'm still getting the MAXIMUM DEBUG LOG SIZE REACHED – Nick Kahn Sep 30 '15 at 14:04
  • @AbuHamzah What release is your Org on? Is it Winter '16 or Summer '15? If you download the log from the developer console the very first line will tell you the logging levels that where applied for each category. – Daniel Ballinger Sep 30 '15 at 19:59
5

Debug statements shouldn't generally be used. Instead, in the console, go to the line of code where you want a snapshot, cluck the line number to create a checkpoint, then run the test. Afterwards, visit the checkpoint tab, and you can view the contents of memory when the checkpoint was reached. It will show you all the variables in memory during the unit test at that point.

  • 2
    Can you clarify why debug statements shouldn't be used generally? Is it the performance impact? – Daniel Ballinger Sep 29 '15 at 19:04
  • 1
    Note that in Do Checkpoints work with Unit Tests? I found that checkpoints would only work if the Apex Code tracing level was set to Finer or Finest. This shouldn't be a problem if you don't have any other logging going on, but it is something to keep in mind if you want to see the checkpoint output. – Daniel Ballinger Sep 29 '15 at 19:17
  • 2
    @DanielBallinger (a) They won't show you the full state of the system, (b) performance, because people forget to remove them later, and (c) you have to edit code instead of just clicking a line number, which affects (b). However, logging in Winter 16 seems to favor debug statements (I just tested this), but if you need 20-30 debug statements, then checkpoints are ideal. In our code base, for example, we have 450 debug statements, some of them in loops. Our system is horribly slow as a result... – sfdcfox Sep 30 '15 at 4:47
  • @sfdcfox: I have not used the above approach you have talked about breaking point on the line number and I did attempt to see but I do not see any variables in memory, so here is what I have done, click on the line number a red dot appeared and run the test the test passed and go to the Tests tab and see the folder but it does not load the variable that I have breakpoints on, I'm missing anything else? – Nick Kahn Sep 30 '15 at 14:07
  • @AbuHamzah Make sure your debug level is set correctly. See Daniel's answer, it already has pretty pictures on how to change levels. – sfdcfox Sep 30 '15 at 20:53
0

Unit tests run with a specific set of debug log levels, and you can't alter these options for unit tests.

If you use the developer console to run your unit tests, you should be able to select your unit test class, and then be able to select individual testMethods to run within that test class.

By running a single testMethod, the resulting log should be under the Max Debug Log Size, even with the painful verbosity of the unit test debug log levels.

There is an idea on the ideaExchange to allow setting the unit test debug log levels https://success.salesforce.com/ideaView?id=08730000000iKMpAAM

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.