How do I run unit tests against datasets? (DrupalWebTestCase and DrupalTestCase)
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.