我需要测试帐户中的功能。但是为此需要注册一个帐户。如果该功能无法正常运行并且测试失败,我如何自动从数据库中删除一个帐户(在测试过程中创建的帐户)?
I need to test the feature in account. But for this need register an account. If the feature does not work correctly and the test fails, how do I can automatically delete an account from a database (account created during testing)?
推荐答案我认为您有一些选择。
您可以在Cest类的_before或_after方法中进行清理(如果使用框架,则可以例如,使用ORM删除所有帐户。)
You can do clean-up in your Cest class's _before or _after methods (if you use a framework you could use an ORM to delete all accounts for example).
Codeception的Db模块(请参见 codeception/docs/modules/Db )也有一个清理标志,当为true时,它将在每次测试之前加载用户定义的数据库转储(您可以创建
Codeception's Db module (see codeception/docs/modules/Db) also has a cleanup flag which, when true, will load a user-defined database dump before each test (you could create a dump with no accounts).
可能还有其他选择。例如,如果您使用Yii2,则用于Codeception的Yii2模块具有清除标志,如果为true,该标志将在测试中包装测试(请参见 codeception/for/yii )。
There might be other options too. If you use Yii2 for example, the Yii2 module for Codeception has a cleanup flag that will wrap tests in a transaction if true (see codeception/for/yii).
更多推荐
如果测试失败,如何在代码接收中使数据库回滚?
发布评论