开发者

Database/model fixtures and original state

I am starting to work on improving my testing practices, and have been reading about the use of Fixtures in the Yii Framework, as well as in Rails. While I understand the basic idea of fixtures--that they load a specific set of data before each test--I'm not clear on what happens with the pre-test database state. While these tests would obviously not be run on a production instance, there still may be some data in the development models that I wouldn't want wiped out every time I ran some tests. Could you help me clear up this bit of background knowledge about fixtures an开发者_StackOverflow社区d unit testing?


Basically any test class that you derive of CDbTestCase will attempt to import the fixtures in its setUp function.

Noteworthy is also that if you do not declare the $fixtures variable in your own class it will import the entire set of fixtures that you have (so what speed is regarded if you have a lot of tests it is best to add only what you need)

If you have tables that require specific data to be there in advance and you don't change it during testing (as in a Products table for example), then you just make sure that table is in the database and you don't create a fixture for it. Yii will not touch the table and it can be used as expected.


Your tests run against your test database, while your dev work hits your development environment (as set up in the database yml file). The test environment is there so that you can put it in a known state without effecting any data you use when "poke testing" a running app.

Hope that helps clear it up a bit.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜