更新数据库表的方法应如何进行单元测试? [英] How should methods updating database tables be unit tested?

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

问题描述

我有一个数据库密集型应用程序。大多数应用程序方法都在更新数据库中的数据。一些调用是存储过程的包装,而另一些调用则使用第三方API以代码形式执行数据库更新。

I have an application that is database intensive. Most of the applications methods are updating data in a database. Some calls are wrappers to stored procedures while others perform database updates in-code using 3rd party APIs.

在单元测试中应该测试什么?我应该...

What should I be testing in my unit tests? Should I...


  1. 测试每个方法是否完成而不会引发异常-or-

  2. 每次测试后验证数据库中的数据,以确保数据状态符合预期

我最初的想法是#2,但是我我担心的是,我将编写一堆框架代码与单元测试一起使用。我读到您不应该为单元测试编写一堆框架代码。

My initial thought is #2 but my concern is that I would be writing a bunch of framework code to go along with my unit tests. I read that you shouldn't write a bunch of framework code for unit testing.

有想法吗?

编辑:我所说的框架是在编写大量的其他代码作为单元测试代码的,而不是第三方框架。

What I mean by framework is writing a ton of other code that serves as a library to the unit testing code...not a third party framework.

推荐答案

我执行第2个操作,即通过更新一条记录来测试更新,然后将其读回并验证值是否相同就像您放入的那样。在事务中进行更新和读取,然后回滚它,以避免对数据库造成永久性影响。我不认为这是测试框架代码,仅是我认为它是测试操作系统代码或网络代码而已...应该对框架(如果您是指非应用程序特定的数据库访问层组件)进行测试和验证

I do number 2, i.e., test the update by updating a record, and then reading it back out and verifying that the values are the same as the ones you put in. Do both the update and the read in a transaction, and then roll it back, to avoid permanent effect on the database. I don't think of this as testing Framework code, any more than I think of it as testing OS code or networking code... The framework (if you mean a non-application specific Database access layer component) should be tested and validated independently.

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

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