Yii2: loading fixtures for specific functional tests

不羁的心 提交于 2019-12-24 13:19:34

问题


Short version: Using Yii2 Advanced Application Template and Codeception functional tests, is there a way to load a specific fixture only before a particular scenario (Cest class)?

(Background / side note: I have a vague feeling I might be approaching this wrong, since arguably, if tests should be completely isolated with regards to db, they should be unit tests and not functional ones. However, due to time constraints on the project I started with functional tests while postponing unit testing. I am testing a REST API and have a case which is strongly dependent on the testing data, and fails when the data is modified by other tests.)

One approach I found is to write a new _support\ApiHelper class extending the default FixtureHelper and put the loadFixtures()/unloadFixtures() calls in _before instead of _beforeSuite(). However, this makes all fixtures load before every test, which makes the suite's execution very slow.


回答1:


I found a better approach than the one described in the question: Extend the FixtureHelper class and add a method haveCleanDb which calls unloadFixtures()/loadFixtures(). Then, in the Cest scenario where I need it, I call it in the _before and _after methods: $I->haveCleanDb(). That way, all the other tests are still fast.



来源:https://stackoverflow.com/questions/31873977/yii2-loading-fixtures-for-specific-functional-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!