单元测试数据库方法 [英] Unit Testing Database Methods

查看:45
本文介绍了单元测试数据库方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发一个使用 SQLite 数据库的 c# 项目.对于该项目,我需要进行单元测试,但被告知单元测试不应涉及外部文件,例如用于测试的数据库文件,而测试应模拟数据库.

I am currently working on a c# project which makes use of an SQLite Database. For the project I am required to do unit testing but was told that unit testing shouldn't involve external files, like database files for the testing and instead the test should emulate the database.

如果我有一个函数来测试数据库中是否存在某些东西,那么如何通过单元测试来测试这种方法.

If I have a function that tests if a something exists in a database how could this sort of method be tested with a unit testing.

推荐答案

使用 SQLite,您可以使用 in-内存数据库.您可以通过插入数据来暂存数据库,然后针对它运行测试.

With SQLite, you could use an in-memory database. You can stage your database by inserting data and then run your tests against it.

这篇关于单元测试数据库方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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