Why not programatically created nodes in the simpletests? Most core and many contrib simpletest test create nodes by preparing the interface, logging an admin in and then filling out the form on /node/add/foo. Not only is this terribly slow, it fails at the most basic rule of Testing: only test your own concerns; mock and stub the rest.

For a test, all I need is N nodes with X tags (taxonomy-terms) attached to them. I am (in no way) interested in whether or not some "Save" button exists somewhere; which is what I am testing when I follow along with core tests, e.g my helper function createNodesWithTags().

This helper is modeled after TaxonomyRSSTestCase which has the same concern as my: make sure there are some nodes with tags, so that some interface can then be tested using these nodes. The helper first creates an entity-field on the node type "article", required because otherwise one cannot add tags to that node. It then proceeds to open up the node/add/article-page, attaches the term and presses Save.

  private function createNodesWithTags($amount) {
    $field = array(
      'field_name' =&gt; 'taxonomy_' . $this-&gt;vocabulary-&gt;machine_name,
      'type' =&gt; 'taxonomy_term_reference',
      'cardinality' =&gt; FIELD_CARDINALITY_UNLIMITED,
      'settings' =&gt; array(
        'allowed_values' =&gt; array(
          array(
            'vocabulary' =&gt; $this-&gt;vocabulary-&gt;machine_name,
            'parent' =&gt; 0,
          ),
        ),
      ),
    );
    field_create_field($field);

    $this-&gt;instance = array(
      'field_name' =&gt; 'taxonomy_' . $this-&gt;vocabulary-&gt;machine_name,
      'bundle' =&gt; 'article',
      'entity_type' =&gt; 'node',
      'widget' =&gt; array(
        'type' =&gt; 'options_select',
      ),
      'display' =&gt; array(
        'default' =&gt; array(
          'type' =&gt; 'taxonomy_term_reference_link',
        ),
      ),
    );
    field_create_instance($this-&gt;instance);

    //Create N nodes and attach all N to tag1, N-1 to tag2, N-2 to tag3 etc.
    $attachable = $this-&gt;tags;
    for ($i = 0; $i &lt; $amount; $i++) {
      // Post an article.
      $edit = array();
      $langcode = LANGUAGE_NONE;
      $edit["title"] = $this-&gt;randomName();
      foreach($attachable as $tag) {
        $edit[$this-&gt;instance['field_name'] . '[' . $langcode . '][]'] = $tag-&gt;tid;
      }
      $this-&gt;drupalPost('node/add/article', $edit, t('Save'));

      //remove one tag, so the next node gets one less tag attached.
      array_shift($attachable);
    }
  }


Why do core tests test this way? Why is TaxonomyTestCase concerned with whether or not saving a node works (i.e. an admin can be created, logged in and finds the Save button)? Why don't they just call node_save() or some other API? 

Is there a reason why I should implement it this way too, instead of just dropping records in the database, possible trough the node_save() API?
Here is what the Drupal documentation says on it's simpletest page.


  Testing methodology
  Drupal testing focuses on functional testing
  instead of unit testing. What this means is that the tests are written
  in such a way that they test the interface as a whole instead of
  testing individual functions or finite pieces of code. Drupal focuses
  on functional testing because it is more effective for the way Drupal
  is written. Functional testing ends up being just as effective if not
  more effective than unit testing and especially so due to the code
  style used in Drupal. The testing framework is geared towards this
  type of testing and the documentation focuses on writing functional
  tests.


Drupal tests are almost always functional tests and not unit tests. As quoted above, Drupal was coded in such a way (e.g. hooks system, forms api, etc) that Unit tests generally don't make sense.