christophrumpel's avatar

New dump for every Codeception test?

Hey,

I've been working with Codeception in my latest project and what I find strange is the DB module.

So after every test CC restores my DB from the dump I provide. But that means I need to create a new dump every time I run my tests? (when I want to clear the data created)

Wouldn't it be of more use if CC creates automatically a dump before running the test and then resets to my current DB data like it was before the test?

  1. Do you all create a dump every time you test?

  2. Or does it not matter cause you only have test data locally and you do not need to restore every time?

0 likes
5 replies
MikeHopley's avatar
Level 17

Well, Codeception should never be hitting a database that has "real" data anyway. Normally you would have a separate "testing" database even on localhost.

That way you can separate the data for "me testing the website" from the data for "Codeception testing the website".

Maintaining the DB dumps can be a pain though. I wrote an Artisan command to refresh all my local databases, including the Codeception dump.

I would not advise running Codeception against the production site, regardless. It's just too easy to screw up and accidentally wipe the production database.

1 like
christophrumpel's avatar

That sounds reasonable. Guess I need a little shift on my thinking. Thx!

zs42311's avatar

To continue on this topic, How do I set up a testing database.

That is, i have created a testing database, my question is how do I configure codeception to use it?

Do I need to make a .env.testing file (with test database in it), and some codeception's .yml files?

Which ones? :)

MikeHopley's avatar

@blackbird Actually I was assuming we were talking about acceptance tests! See below...

@christophrumpel I may have jumped to conclusions here when I read "So after every test CC restores my DB from the dump I provide." I didn't read your post very well.

My understanding is that this was the usual setup for acceptance tests: use mysql, and provide a dump for Codeception to restore from. If you read the Codeception docs, that's what they suggest; and people here have had trouble trying to use another solution like migrating the database.

With functional tests, I thought the normal solution is either (a) migrate and seed a testing database (mysql or sqlite) or (b) use sqlite and restore from a file (which is about 15 times faster).

Where you are restoring from a file or a dump, you might need to update it occasionally. You can write an Artisan command to do this for you.

It seems there are several variations you can use. With functional tests (i.e. "database tests"), I would avoid using a mysql dump because I think it would slow down these tests excessively. With acceptance tests, which are pretty slow already especially in Webdriver, it's not much of an issue; and also this seems to be what Codeception expects you to do.

Please or to participate in this conversation.