用TDD编写DAL [英] Writing a DAL with TDD

查看:68
本文介绍了用TDD编写DAL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我终于开始使用TDD(测试驱动开发)了,哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇!我第一次尝试从怀疑论者到真正的信徒。


我的问题:根据我读过的各种书籍和文章

TDD,一个好的单元测试不依赖于数据库或其他此类

外部/环境条件。更一般地说,一个好的单元测试是原子的,并且对其运行时环境的假设很少,因为它可能是b / b
。但是为DAL开发单元测试怎么样 - 生活中的目的是为了与数据库进行交互?


您的想法和意见表示赞赏。 />

I''ve finally gotton board with TDD (test driven development) and wow is it
effective! I went from sceptic to True Believer with my first effort.

My question: According to the various books and articles I have read about
TDD, a good unit test does not rely on the database or other such
external/environmental conditions. More generally, a good unit test is
atomic and makes as few assumptions about its runtime environment as
possible. But what about developing unit tests for a DAL - whose purpose in
life is to interact with a database?

Your thoughts and opinions are appreciated.

推荐答案

4月23日上午11点16分,Cramer < A ... @B.comwrote:
On Apr 23, 11:16 am, "Cramer" <A...@B.comwrote:

我终于用TDD(测试驱动开发)了解了它并且哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇b $ b有效!我第一次尝试从怀疑论者到真正的信徒。


我的问题:根据我读过的各种书籍和文章

TDD,一个好的单元测试不依赖于数据库或其他此类

外部/环境条件。更一般地说,一个好的单元测试是原子的,并且对其运行时环境的假设很少,因为它可能是b / b
。但是为DAL开发单元测试怎么样 - 生活中的目的是为了与数据库进行交互?


您的想法和意见表示赞赏。
I''ve finally gotton board with TDD (test driven development) and wow is it
effective! I went from sceptic to True Believer with my first effort.

My question: According to the various books and articles I have read about
TDD, a good unit test does not rely on the database or other such
external/environmental conditions. More generally, a good unit test is
atomic and makes as few assumptions about its runtime environment as
possible. But what about developing unit tests for a DAL - whose purpose in
life is to interact with a database?

Your thoughts and opinions are appreciated.



我会测试DAL中的行为。我不太熟悉DB

编程

但据我所知,DAL抽象了一堆SQL语句或调用

to

数据库中的存储过程。


所以我会测试设置实际的

隧道调用的适配器对象数据库。

理由是,如果你已经验证了设置适配器对象的行为,那么它将会正常工作你连接一个实际的数据库。


如果Adapter对象不能被模拟为direclty,那么我会写一个

简单的包装器

,嘲笑适配器。

I would test the behavior in the DAL. I m not very well versed with DB
programming
but, as far as i know DAL abstracts a bunch of SQL statements or calls
to
stored procedures in the DB.

So I would test for setting up the adapter object that actually
tunnels the call to the DB.
The rationale is that if you have validated the behavior that sets up
the adapter object,
then it will work correctly when you connect a actual DB.

If the Adapter object cannot be mocked direclty, then I would write a
simple wrapper around
that, that mocks the adapter.




" Cramer" < A@B.com在留言中写道

新闻:eZ ************** @ TK2MSFTNGP03.phx.gbl ...

"Cramer" <A@B.comwrote in message
news:eZ**************@TK2MSFTNGP03.phx.gbl...

我终于通过TDD(测试驱动开发)获得了董事会,哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇哇!我第一次尝试从怀疑论者到真正的信徒。


我的问题:根据我读过的各种书籍和文章

TDD,一个好的单元测试不依赖于数据库或其他此类

外部/环境条件。更一般地说,一个好的单元测试是原子的,并且对其运行时环境的假设很少,因为它可能是b / b
。但是为DAL开发单元测试怎么样 - 其目的是生活中的
与数据库交互?


您的想法和意见表示赞赏。
I''ve finally gotton board with TDD (test driven development) and wow is it
effective! I went from sceptic to True Believer with my first effort.

My question: According to the various books and articles I have read about
TDD, a good unit test does not rely on the database or other such
external/environmental conditions. More generally, a good unit test is
atomic and makes as few assumptions about its runtime environment as
possible. But what about developing unit tests for a DAL - whose purpose
in life is to interact with a database?

Your thoughts and opinions are appreciated.



您可以通过与DAL交互的Business

图层的接口对DAL进行单元测试。


此链接显示TDD和TDD解决方案的单元测试。

http://www.polymorphicpodcast.com/

还有这个可以告诉你如何开发解决方案,以及如何

你可以通过界面测试。您应该能够为界面开发测试

线束或使用Nunit线。

MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/


点击''显示''


点击''设计模式训练营:模型视图*模式*


查看零件1-5

You could do the unit test of the DAL through the interfaces of the Business
layer that interacts with the DAL.

This link has shows about TDD and unit testing of a TDD solution.

http://www.polymorphicpodcast.com/

There is also this which can show you how to develop your solutions, and how
you can test through the interface. You should be able to develop a test
harness for the interface or use something line Nunit.
MODEL-VIEW-PRESENTER

http://www.polymorphicpodcast.com/

click ''Shows''

click ''Design Patterns Bootcamp: Model View * Patterns*

view parts 1-5


Cramer写道:
Cramer wrote:

我终于用TDD(测试驱动开发)和哇

有效!我用第一个

的努力从怀疑论者变成真正的信徒。

我的问题:根据我读过的各种书籍和文章

about TDD,一个好的单元测试不依赖于数据库或其他这样的外部/环境条件。更一般地说,一个好的单元

测试是原子的,并尽可能少地假设它的运行时间b $ b环境。但是开发单元测试怎么样呢?它的生活目的是与数据库进行交互?
I''ve finally gotton board with TDD (test driven development) and wow
is it effective! I went from sceptic to True Believer with my first
effort.
My question: According to the various books and articles I have read
about TDD, a good unit test does not rely on the database or other
such external/environmental conditions. More generally, a good unit
test is atomic and makes as few assumptions about its runtime
environment as possible. But what about developing unit tests for a
DAL - whose purpose in life is to interact with a database?



单元测试需要在已知状态下创建一个新数据库,使用

打开它,测试DAL,验证结果,清理数据库。

The unit test needs to create a new database in a known state, open it using
the DAL under test, verify the results, clean up the database.


>

您的意见和建议表示赞赏。
>
Your thoughts and opinions are appreciated.



这篇关于用TDD编写DAL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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