How do I debug a the output errors on SimpleTest when I'm not sure where in the script the error occurred? I'm trying to build a simple test. I'm having trouble submitting webforms. With help form a previous question I've cobbled together these functions within the larger class. 

They completely work in the following test.php script run on the command line via drush scr test.php

$data = array(
  1 =&gt; array('1'),
  2 =&gt; array('2'),
  3 =&gt; array('3')
);

$T = new MyTest();
$T-&gt;insertMockData($data);


However, when I try to run as `drush test-run MyTest things fail completely.

Source snippet: 

  function setUp($modules = array()) {
        $modules[] = 'webform';
        parent::setUp($modules);

        $this-&gt;insertMockData($this-&gt;randomData());
    }
function insertMockData($data = array(), $submitted_datetime = REQUEST_TIME) {

        $node_web = node_load(1);
        $submission = (object) array(
        'nid' =&gt; $node_web-&gt;nid,
        //'uid' =&gt; $user-&gt;uid,
        'submitted' =&gt; $submitted_datetime,
        'remote_addr' =&gt; ip_address(),
        'is_draft' =&gt; FALSE,
        'data' =&gt; $data,
            'serial' =&gt; $this-&gt;serial_value++,
        );
        module_load_include('inc', 'webform', 'includes/webform.submissions');
        webform_submission_insert($node_web, $submission);
            //webform_submission_send_mail($node_web, $submission);
          }

    function randomData() {
    $random_line_of_text  = array(
      "Mary had a little lamb",
      "a little lamb",
      "With fleece as white as snow",
      "And everywhere that Mary went",
      "That lamb was sure to go");

    return array(
      1 =&gt; array($random_line_of_text[array_rand($random_line_of_text)]),
      2 =&gt; array($random_line_of_text[array_rand($random_line_of_text)]),
      3 =&gt; array($random_line_of_text[array_rand($random_line_of_text)]),
    );
}


Errors on console 

Test MyTest-&gt;insertMockData() failed: Trying to get property of non-object                       [error] Test webform_webform_submission_presave() failed: Trying to get property of non-object             [error] 
Test webform_webform_submission_presave() failed: Invalid argument supplied for foreach()          [error] Test webform_submission_insert() failed: Trying to get property of non-object                      [error] 
Test webform_submission_insert() failed: Trying to get property of non-object                      [error] Test webform_submission_insert() failed: Trying to get property of non-object                      [error] 
Test webform_submission_insert() failed: Trying to get property of non-object                      [error] Test webform_submission_send_mail() failed: Trying to get property of non-object                   [error] 
Test webform_submission_send_mail() failed: Invalid argument supplied for foreach()                [error] Test MyTest-&gt;insertMockData() failed: Trying to get property of non-object                       [error] 


Question: How do I debug a the output of SimpleTest when I'm not sure where in the script the error occurred?
Part of why your test is failing is pretty easy to see.  Your code is relying on node 1 existing:

function insertMockData($data = array(), $submitted_datetime = REQUEST_TIME) {

        $node_web = node_load(1);
        $submission = (object) array(
        'nid' =&gt; $node_web-&gt;nid,
        //'uid' =&gt; $user-&gt;uid,
        'submitted' =&gt; $submitted_datetime,
        'remote_addr' =&gt; ip_address(),
        'is_draft' =&gt; FALSE,
        'data' =&gt; $data,
            'serial' =&gt; $this-&gt;serial_value++,
        );
  //lots of stuff omitted here...
}


The code assumes that there's a node in your DB for you to load.  Sadly, no :-)

When SimpleTest runs, it creates a whole empty DB that's just installed.  If you need a node, you have to create one, like this:

$settings = [
  'title' =&gt; 'My Test Content',
  'body'  =&gt; 'and what a body it is',
  'status' =&gt; 1,
  'type' =&gt; 'article',
];

$test_node = $this-&gt;drupalCreateNode($settings);
$this-&gt;assertNotNull($test_node, "Make sure our settings work");


See core/modules/simpletest/src/WebTestBase.php for some of the methods you can use to create nodes and users and other useful test data.  But in general: your test or the test's superclasses need to create everything you need either in setUp() or in your test itself.