Create Test Data in the Database

In order to test the physical and logical database connect, I don’t use Mockups here (we’ll do that later on), but I create database test data via an instance of the phpunit Test Framework in the setUp() method (see the prior post). Later on (while testing) I can use this data to read it from the database, change it and store it back into the database. While doing this I will check the correctness and consistency of all transferred data.

To create unique test data, I simply use a unique id that defines the data:


protected function setupTestData($number) {
    $now = time();
    $uid = $this->testingFramework->createRecord(
        'tx_csevents_appointments',
        array(
            'internal_id' => 'Test Title #' . $number,
            'listas' => 'List as #' . $number,
            'stime' => $now,
            'letin' => $now - 15*60,
            'etime' => $now + 90*60,
            'places' => 70,
            'soldout' => 0
        )
    );
    return $uid;
}

This is simple, but very efficient. You can use more complex test data generators (e.g. with more varying parameters) to achieve a better test coverage. Think of equivalent class testing for instance.

Note for those, who are not that familiar with testing strategies: If you want to understand Equivalent Class Testing just think of a field where it’s required to enter a price between 0 and 1.000,-€ (including). To test this field, you should test the following values:

  • -1,-€ shall fail
  • 0,-€ shall succeed
  • 1,-€ shall succeed
  • some random value between 1,- and 1.000,-€ shall succeed
  • 999,-€ shall succeed
  • 1.000,-€ shall succeed
  • 1.001,-€ shall fail

…and of course you can just drill this down to € Cents as well – and do tests for $ additionally. There is a lot of room for improvement, but this will tell you the basic idea of Equivalent Class Testing: Test the borders of allowed / valid values from both sides (the allowed and the discarded side) and don’t forget to test the border itself as well (e.g. “0€” including or excluding?!). This is, where most of the GUI defects occur.

Leave a Reply