在进行单元测试时,是否必须使用数据库来测试CRUD操作? [英] When unit testing, do you have to use a database to test CRUD operations?

查看:469
本文介绍了在进行单元测试时,是否必须使用数据库来测试CRUD操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在进行单元测试时,在测试CRUD操作时是否必须使用数据库? sql lite可以解决这个问题吗?您是否必须以某种方式在内存中创建数据库?

When unit testing, is it a must to use a database when testing CRUD operations? Can sql lite help with this? Do you have to cre-create the db somehow in memory?

我正在使用mbunit.

I am using mbunit.

推荐答案

否.集成实际的数据库将是集成测试.不是单元测试.

No. Integrating an actual DB would be integration testing. Not unit testing.

是的,如果您不能以任何其他方式抽象(模拟)DAL/DAO,则可以使用诸如 SQLite MS SQL Compact 之类的任何内存数据库方式.

Yes you could use any in-memory DB like SQLite or MS SQL Compact for this if you can't abstract (mock) your DAL/DAO in any other way.

有鉴于此,我必须指出,从DAL一直到单元测试都是可能的,但DAL本身不可能.在集成测试中,必须使用某种实际的数据库对DAL进行测试.

With this in mind I have to point out, that unit testing is possible all the way to DAL, but not DAL itself. DAL will have to be tested with some sort of an actual DB in integration testing.

这篇关于在进行单元测试时,是否必须使用数据库来测试CRUD操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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