English 中文(简体)
如何对数据库进行单位测试取决于行为C#
原标题:How to unit test database depended behavior C#


I have a C# application which communicates with DB. I want to test some functions which depend on DB. So I want to be sure that DB has an initial state before each test run. I use NUnit to test my application. What means are available to restore an initial state of DB?
Thank you for your help!

最佳回答

你们可以在记忆库数据库中用于创造试验环境。

http://www.dotnetguy.co.uk/post/2009/10/20/sqlite-nunit-fluent-nhibernate-test-your-data-access-layer/“rel=” 缩略语

问题回答

As others have said, you must NOT depend on a DB and it s structure in unit-testing. Hence I would create an Interface which hides the DB from the component which uses it (aka DB abstraction layer) and then implement an in-memory-DB for the sake of unit-testing.

可通过每个非行表格使用简单的C# HashT表执行该非行的表格。

这种地震还有助于在行文中将行文分离,从而可能改变(例如从MySQL移至Oracle等)的成分。

你们应当使用模拟方案,例如:

Rhino mocks or moq

这些方案可以在测试期间模拟数据来源,如数据库。

Consider switching to MbUnit for your integration tests. It has very handy Rollback attribute exactly for your needs.

MbUnit与NUnit一样具有标识测试类别和方法的特性。 因此,你只需要改变指令和参考MbUnit dll。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签