Welcome Guest, Not a member yet? Register   Sign In
Testing: Database refresh and migrations

(07-03-2020, 03:30 PM)MGatner Wrote: That’s exactly the case I’m talking about. Since you don’t wipe the database between tests, let me ask: how are you setting up the database initially?

I think I might not interpreted your question as you intended. I do a complete initialization on the database once for a test cycle of about ~ 420 individual tests as of now. So my input here might not be relevant. 

If you meant that database should be fully initialized once, and then somehow restore it to its original state between each run considerably faster than a full initialization, then I would research DB restoration tools or methods of some sort. Like Point In Time recovery with PgSQL, which might be faster, depending on how many alterations happen during the tests. But it is cumbersome and might not even be possible in other than development / test environment.

Anyways, I do this as a test itself like this (no surprise):
PHP Code:
class InitDatabaseTest extends CIDatabaseTestCase
    protected $refresh true;
    protected $seed 'InitDatabaseSeeder';
    protected $basePath TESTPATH  .'../app/Database';
    protected $namespace 'App';

    public function testSeedUsers()
        $this->seeInDatabase('user', ['username' => 'john.doe']);

where InitDatabaseSeeder contains all the INSERT statements to fill the DB with initial data.

Messages In This Thread
RE: Testing: Database refresh and migrations - by bivanbi - 07-04-2020, 03:37 AM

Theme © iAndrew 2016 - Forum software by © MyBB