在内存中填充 SQLite 进行单元测试 [英] Populating SQLite in memory for unit testing

查看:61
本文介绍了在内存中填充 SQLite 进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑使用 SQLite 作为我的 Oracle 数据库的内存存根.我可以轻松地将所有 DAL 命令定向到 SQLite,但我现在想知道如何轻松地为每个测试方法填充数据.
每种方法是否应该首先创建所需的表并插入特定测试的行?我应该在 Fixture SetUp 阶段填充内存中的数据吗?有没有其他方法(比如从某个文件中读取它,但放弃更改以便下一次读取相同)?
也许我应该用一个普通的存根存根数据库,并在需要时返回本地创建的对象(数据集和数据表)?我想尝试这个,但这样我不会测试传递的实际查询,我正在尝试对执行 SQL 选择的方法进行单元测试.我还想测试查询的语法和有效性.

I am thinking of using SQLite as an in memory stub for my Oracle database. I can easily direct all my DAL commands to the SQLite, but I am now wondering how I should easily populate the data for each test method.
Should each method begin by creating the needed table(s) and inserting the rows for the specific test? Should I populate in the Fixture SetUp phase the data in the memory? Is there some other way (Like reading it from some file, but discarding the changes so that the next read will be the same)?
Maybe I should just stub the db with a normal stub, and return locally created obejcts when needed (DataSets and DataTables)? I thought about trying this, but this way I will not be testing the actual queries passing along, and I am trying to unit test methods that perform SQL selects. I want to test the syntax and validity of the queries as well.

关于此的任何最佳实践?还是只是好主意?

Any best practices regarding this? Or just good ideas?

推荐答案

只备份 SQLite-Db-File 怎么样?

How about just backing up the SQLite-Db-File?

SQLite 的好处是,您可以随意复制整个 db 文件.您还可以使用 SQL 文件来用数据填充某些 db 文件.我不完全理解您的问题,但是混合使用 db 文件(作为模板)和(可选)一些 SQL 文件来根据需要填充表应该足以解决非常困难的测试问题.

The good thing about SQLite is, that you just can copy the whole db-file as often as you want. You can also have SQL-files to populate some db file with data. I don't understand your problem totally, but with a mixture of db files (as templates) and (optionaly) some SQL-Files to fill tables as needed should suffice for also very difficult testing issues.

还可以通过转储简单文件和(可选)删除不需要的条目或添加其他条目来轻松创建 SQL 文件.

The SQL-Files can also easily created by dumping simple files and (optionaly) deleting unwanted entries or adding additional ones.

这篇关于在内存中填充 SQLite 进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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