4

In my current company I am trying to introduce functional/api testing with database, and I am kind of hit the wall. So company and their product was around for a very long time, the size of skeleton mysql database (without or only necessary data) is over 300mb. It takes up to 5 minutes to import it.

Now idea initially was, that when developer runs tests, database is automatically imported (with unique name), migrations are ran, tests are ran, and then in the end database is dropped. Obviously this approach is counter productive, especially for TDD, if something changes, you need to wait 5 minutes to import database alone.

It’s also worth mentioning, that most developers work in single server, and also share mysql server (which is shared by everyone in company), so we would like to prevent junk databases (that are created during testing) and save some space, this why we wanted automatically import and drop db each time.

Also tests are ran in transactions, so in theory same database should be reusable (unless tested code already uses transaction, then it’s fucked up...).

I thought about separating import and drop functionality into custom commands, then developer could import and drop db on demand (and it would make sense). Then also have a cron script which would clean up those databases every night. It seems like the best solution at this moment.

Anyway, I have some time until our architect is back in office and we can discuss it, so I figured, I will ask fellow devranters, do you have any recommendations? How do you manage your functional tests and databases?

Comments
  • 1
    300mb db takes 5 minutes, are you using a client to import that thing?

    # mysql database_name < database_name.sql --triggers
  • 0
    @C0D4 well, roughly, maybe less, but enough to get annoyed and distracted (as that xkcd comic). Yeah, I use mysql client, though probably should play a little bit flags as to ignore comments, maybe that would improve performance a little, but still if test takes a second to run, and database minute to import, that’s no fun.
Add Comment