如果测试失败,如何在代码接收中使数据库回滚?

编程入门 行业动态 更新时间:2024-10-25 00:36:59
本文介绍了如果测试失败,如何在代码接收中使数据库回滚?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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).

更多推荐

如果测试失败,如何在代码接收中使数据库回滚?

本文发布于:2023-11-07 00:46:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1565101.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:代码   数据库   测试   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!