如果测试失败,如何在代码接收中使数据库回滚? [英] How in codeception to make rollback a database if the test failed?

查看:108
本文介绍了如果测试失败,如何在代码接收中使数据库回滚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要测试帐户中的功能。但是为此需要注册一个帐户。如果该功能无法正常运行并且测试失败,我如何自动从数据库中删除一个帐户(在测试过程中创建的帐户)?

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模块(请参见 https://codeception.com/docs/modules/Db )也有一个清理标志,当为true时,它将在每次测试之前加载用户定义的数据库转储(您可以创建

Codeception's Db module (see https://codeception.com/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,该标志将在测试中包装测试(请参见 https://codeception.com/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 https://codeception.com/for/yii).

这篇关于如果测试失败,如何在代码接收中使数据库回滚?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆