Current section: Test Database 5 exercises

Optimizing Test Setup

Loading exercise


00:00 Like I said, I'm not super jazzed about how long this is taking, and the reason it's taking so long is because every single process needs to create its own test database and run all the migrations and everything. So, that's not awesome. What we're going to do in this exercise is we actually are going to create a, what I'm calling a base test database.

00:17 So, this is the test database upon which other databases can be based. So, basically the idea is we make a single test database, and then when the other processes start, they just copy that one over, and then they move forward with their test. So, it should be a lot faster,

00:34 because copying a file is a lot faster than running all the migrations and everything, and we still maintain the benefit of being in total isolation. The other thing that we're going to do to make all this work is we're going to use the global setup config in vTest that will allow us to say, hey, before you run any tests,

00:53 then I want you to run this first. And so, that will be the part where we're creating the test database, and then it will run the tests, and each test will just go and copy that base database. Now, as a part of this, we're also going to make it so that if the base database already exists, we won't even bother running the migrations.

01:13 And so, we're going to leave that base database around. We're not going to delete it like we're doing with the databases that we have now. We'll just leave it around. And so, every single time you run your tests, when you start it up, if there's already a base database, it'll just get going right from the get-go. So, these will run way, way faster, especially after you get that base database set up for the first time.

01:32 So, I think you'll have a good time with this. There's a couple of moving parts and stuff and a little bit of config. I think you'll have fun. We'll see you when you're done.