使用ado.net应用程序块进行单元测试 [英] Unit Test with ado.net application block

查看:75
本文介绍了使用ado.net应用程序块进行单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我打算在我的项目中编写单元测试。我正在使用ADO.NET应用程序块库来执行数据库操作。



我想为插入,更新和删除方法编写测试方法。我的要求是在数据库中插入或更新虚拟记录后,我想从数据库端清理该数据,我想在TestCleanUp方法中回滚数据,但我不知道如何在TestCleanUp方法中编写代码使用ADO.NET应用程序块从dababase端回滚数据。



任何文章或指导对我都有帮助。



下一个问题:我应该为测试方法创建虚拟数据库吗?



谢谢

Imrankhan

Hi All

I am going to write Unit Test in my project. I am using ADO.NET application block library to perform database operation.

I want to write Test Methods for Insert, Update and Delete methods. My requirement is after inserting or updating dummy records in database, I want to clean up that data from database side, I want to rollback data in TestCleanUp method but I don't have any idea that how do I write the code in TestCleanUp method to rollback data from dababase side by using ADO.NET application block.

Any article or guidance would be helpful to me.

Next Question: Should I create dummy database for Test methods?

Thanks
Imrankhan

推荐答案

您没有分享有关方法的任何细节。在 TestCleanUp 方法中写出适当的查询(DELETE)。



但请勿打扰开发数据库。创建一个用于测试的副本。查看这篇文章

在不到2分钟的时间内创建一个示例SQL数据库 [ ^ ]
You didn't share any details about method. Write appropriate query(DELETE) in TestCleanUp method.

But don't disturb development database. Create a copy for testing. Check this article
Create a Sample SQL Database in Less Than 2 Minutes[^]


如果您正在测试的代码与数据库进行对话,则根据定义不是单元测试(它是集成测试)。你真的在这里测试数据库访问代码吗?如果没有,您希望将数据库访问代码放在接口后面,并使用模拟数据库提供程序进行应用程序代码的单元测试,该代码测试记录对其作出的请求并为应用程序代码提供合适的数据来执行。然后检查是否向数据库提供程序发出了相应的请求。



如果您是直接测试数据库接口代码,那么是的,我建议为每个代码创建一次性数据库测试。可以使用少量测试和小样本数据来测试数据库接口代码,因此创建数据库实例应该很快。
If the code you're testing talks to a database, by definition that is not a unit test (it's an integration test). Are you actually testing the database access code here? If not, you want to put the database access code behind an interface and use a mock database provider for the unit tests of application code, which logs the requests that are made to it and provides suitable data for the application code to execute. You then check that the appropriate requests were made to the database provider.

If you are directly testing database interface code, then yes, I recommend creating a throwaway database for each test. Testing the database interface code can be done with a small number of tests and small sample data so creating a database instance should be fast.


这篇关于使用ado.net应用程序块进行单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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