Where can I read the debug output of test classes

  • Suppose I have a test class TestClassName.

    @isTest
    private class TestClassName {
    static testMethod void testMethodName() {
            System.debug('My debug statement');
            System.assertEquals(1, 1);
        }
    }
    

    Where can I find the log that has the 'My debug statement' output?

    It seems that:

    • Force.com shows the log of the actual ClassName class
    • Developer console shows the log of the actual ClassName class
    • Debug Logs doesn't show the logs of the TestClassName test class
    • Apex Test Execution doesn't show any logs

    You should be able to see the logs of the test class in the developer console, monitored debug logs, and if you are running the tests from eclipse the eclipse test results window. This is probably an issue with your log levels but can you write up how you are running the tests to help us troubleshoot.

  • When you run your test class the debug log does show the logs of even your test execution.

    You have to find the user that started the test in question. The user can be found by going to Setup > Develop > Apex Test Execution and inspecting the Test run to find the email of the user.

    The line will look like this:

    Test run: yyyy-mm-dd hh:MM:ss, [email protected] (n class[es])

    Then at Setup > Monitoring > Debug Logs add the user who has the [email protected] email to Monitored Users.

    Log 
    27.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISmmUALFORCE,INFO;WORKFLOW,INFO
     07:54:37.375 (2375302000)|EXECUTION_STARTED
     07:54:37.375 (2375362000)|CODE_UNIT_STARTED|     [EXTERNAL]|01p90000002IZE6|TestClassName.testMethodName
      07:54:37.376 (2376542000)|METHOD_ENTRY|   [2]|01p90000002IZE6|TestClassName.TestClassName()
     07:54:37.376 (2376557000)|METHOD_EXIT|[2]|TestClassName
     07:54:37.376 (2376695000)|SYSTEM_METHOD_ENTRY|[4]|System.debug(ANY)
      07:54:37.376 (2376721000)|USER_DEBUG|[4]|DEBUG|My debug statement
      07:54:37.376 (2376731000)|SYSTEM_METHOD_EXIT|[4]|System.debug(ANY)
      07:54:37.376 (2376752000)|SYSTEM_METHOD_ENTRY|[5]|System.assertEquals(ANY, ANY)
      07:54:37.376 (2376776000)|SYSTEM_METHOD_EXIT|[5]|System.assertEquals(ANY, ANY)
       07:54:35.608 (2376798000)|CUMULATIVE_LIMIT_USAGE
       07:54:35.608|LIMIT_USAGE_FOR_NS|(default)|
       Number of SOQL queries: 0 out of 100
       Number of query rows: 0 out of 50000
       Number of SOSL queries: 0 out of 20
      Number of DML statements: 0 out of 150
      Number of DML rows: 0 out of 10000
       Number of code statements: 2 out of 200000
      Maximum heap size: 0 out of 6000000
      Number of callouts: 0 out of 10
      Number of Email Invocations: 0 out of 10
      Number of fields describes: 0 out of 100
     Number of record type describes: 0 out of 100
      Number of child relationships describes: 0 out of 100
     Number of picklist describes: 0 out of 100
     Number of future calls: 0 out of 10
    

    07:54:35.608|CUMULATIVE_LIMIT_USAGE_END

    07:54:37.376 (2376826000)|CODE_UNIT_FINISHED|TestClassName.testMethodName
    07:54:37.376 (2376835000)|EXECUTION_FINISHED
    

    Can you share step-by-step instructions to get to the log? If I add the appropriate user to Monitored Users, the logs still don't show any activities at the time of tests.

    Its very simple.First you have to find the User for which you are running test class.In debug log set that user and refresh.I have updated my answer too with debug log i obtained for your class.Hope it helps

    Hint the logs never showed any activity signifies that he is not the right user .

    You are right! I had to put the user who started the test to Monitored Users. One can find that user on the `Test Run: [date time], [email]` line at Apex Test Execution.

    Happens !Glad that i was able to help:)

License under CC-BY-SA with attribution


Content dated before 7/24/2021 11:53 AM