I am testing a module that I am writing against the Unit Testing framework that comes with Drupal 7. All makes sense, and everything asserts as it should.

My question though, is it possible to run test cases against test data?

I can think of a few options/answers:

  • Trick the unit test into not setting up a test database, and just run against the live data (I don't want to do this, its hackish)
  • It's also very possible that testing against test data is not the place of a unit test, because technically a unit test should pass if there is data or not - from my understand of unit testing.

Should functionality testing be done in a different place than the SimpleTest framework? Or is there a way to test against data sets?

1 Answer 1


Drupal 8 contains tests for verifying an upgrade from Drupal 7 would be executed correctly. Those tests basically create Drupal 7 tables, fill them with the required values, and call update.php.

You could need to create a upgrade/update test for your module, or you could test how a function behaves when it reads data from the database that are not in the format it expects.
In the first case, you would need to override the setUp() method, and avoid calling parent::setUp(); in the second case, you would fill the database table used from the test with the test data, call the function, and check what the return value is.

Apart from testing an update, I can think only of a case where a test would need to fill a database table, since:

  • If the table contains what entered from users, then the test should verify the form validation handler correctly shows error for wrong input

  • If the table contains data entered from another module, that module should be using a function your module implements, and the test should just check what the function does when it receives wrong/unexpected values

It could be your module is using data from a table that is created from another module, which is not exposing an API to load/save data in that table. In that case, if you know there is another module that enters unexpected data, you could need to verify your module is able to handle that data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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