khernik
khernik

Reputation: 2091

Preparing test database

How can I setup a database for testing with my own records when I start executing tests, then work on it, and repeat the process on every action of starting the unit tests?

I mean, where the database should be? Should I create some separate physical database, or add existing test records to it from the code? How can I do that?

Thanks!

Upvotes: 0

Views: 57

Answers (1)

Andras
Andras

Reputation: 692

There is a separate config file for testing. You can find it as config_test.yml. In this config you can set up a test database which will be used only for testing. So you should use a completely separate database.

The next step is creating some initial data. To do this you can use the DataFixtures bundle. Further reading: Symfony DataFixtures

Now you have your initial data. The last step is to purge your test databse every time you run a set of tests. I found a pretty good article about it here: Purging your test database in PHPUnit

So I think this is the best practice for functional testing.

Upvotes: 2

Related Questions