简体   繁体   English

您如何使用 SQFLITE 进行单元测试?

[英]How do you do unit testing with SQFLITE?

I have a database class that handles all my database operations with functions inside it.我有一个数据库 class,它使用其中的函数处理我所有的数据库操作。 How do I make unit tests with this, without it messing up my real database and how do I make it so that it always starts from a clean state?我如何使用它进行单元测试,而不会弄乱我的真实数据库,以及如何使它始终从干净的 state 开始?

One solution is to use sqflite_common_ffi so that you can run unit test on your host (mac, linux, win).一种解决方案是使用 sqflite_common_ffi,以便您可以在主机(mac、linux、win)上运行单元测试。 You can use an in memory database to always start with an empty database without messing your application database.您可以使用 in memory 数据库始终从空数据库开始,而不会弄乱您的应用程序数据库。

More information here:更多信息在这里:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM