针对测试数据库集成测试Web服务 [英] Integration testing web services against a testing database

查看:171
本文介绍了针对测试数据库集成测试Web服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在构建一个使用WCF Web服务,允许一个Flex前端访问数据库的.NET Web应用程序。

I'm currently building a .net web application that uses WCF web services to allow a Flex front end to access the database.

我在设置上的Web服务的一些单位/集成式的测试过程中,我试图找出让测试在一个单独的测试数据库访问和修改数据的最佳方式。

I'm in the process of setting up some unit/integration style testing on the web services and am trying to work out the best way to allow the tests to access and modify data in a separate test database.

目前,在我的单元测试项目点的连接字符串我的测试数据库,并在我的Web服务的项目点,我的开发数据库的连接字符串。但是,因为我使用LINQ看来,当我打电话从我的测试类的Web服务方法,它使用的开发数据库连接字符串。

Currently, the connection string in my unit test project points to my testing database, and the connection string in my web services project points to my development database. However, as I am using Linq it appears that when I call the web service methods from my test class, it uses the development database connection string.

我已经调查创建模拟对象或内存数据库,但我相信会出现同样的问题。

I have looked into creating mock objects or in-memory database but I believe the same issue would occur.

有没有办法得到这个工作,或者是我的整个想法什么我想要不正确,在这种情况下,有没有更好的办法来设置?我还是及早在我的项目,我不是不利显著改变了解决方案的架构。

Is there a way to get this to work, or is my entire idea about what I want incorrect, in which case is there a better way to set this up? I'm still early enough in my project that I'm not adverse to significantly changing the architecture of the solution.

推荐答案

请确保在Web服务中的code是最小的,不是一个简单的调用你的服务层并不多。当你做,你可以跳过直接调用Web服务,并创建一个集成测试套件,还要求你的服务层。在这种情况下,你正在做的一个进程,而不是电话通过网络电话的。在这种情况下,它会更容易,以确保正确访问数据库,你可以很容易地与包装将回滚数据库事务的调用。你当然要回滚任何行动的数据库,因为这将是非常难以维持的 RTM测试的。这样做的一个方法是使用的TransactionScope 内部测试

Make sure the code in the web service is minimal and not much more than a simple call to your service layer. When you do that you can skip calling the web service directly, and create an integration test suite that also calls your service layer. In that case you are doing an in-process call instead of an call over the network. In that situation it will be much easier to ensure the right database is accessed and you can easily wrap those calls with database transactions that will be rolled back. You certainly want to rollback any actions to the database, because it will be very hard to maintain RTM tests. One way to do this is by using TransactionScope inside tests.

祝你好运。

这篇关于针对测试数据库集成测试Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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