在Visual Studio中使用不同项目类型进行集成测试 [英] Integration Testing In Visual Studio With Different Project Types

查看:127
本文介绍了在Visual Studio中使用不同项目类型进行集成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发新的CRM,它在本地用户中使用WPF,在现场用户中使用Windows Universal App(商店应用).基本流程是这样

We are in the middle of developing a new CRM, and it uses both WPF for local users, and a Windows Universal App (Store App) for the users in the field. The basic flow is this

  1. 在WPF应用程序中,客户致电并按现场用户计划.
  2. 现场用户通过通用应用程序进行服务呼叫并在Surface上进行更新.
  3. 从WPF应用中向客户收费.

所有模块都就位并且可以正常工作,但是由于项目类型不同,我似乎无法集成测试整个项目流程.

All the modules are in place and working, but I do not seem to be able to integration test the entire project flow due to the different Project Types.

我需要做的是在WPF应用程序的单元测试中添加对Universal App的引用(或者相反),这样我就可以测试通过这两个组件的流程.

What I need to be able to do is add a reference to my Universal App in the unit test for my WPF app (or the other way around), so I can test the flow through both components.

在过去的几周中,我一直在寻找解决方案,但无法提出任何解决方案.如果这不可能直接实现(我想不可能),那么有什么方法可以设置测试播放列表,以使集成测试按特定顺序运行.

I have been searching for a solution over the last few weeks, and have not been able to come up with any way to do this. If this is not directly possible (which I am guessing it is not), is there any way I can setup a test playlist so that the integration tests run in a particular order.

为了避免测试通用应用程序,我希望避免将示例数据硬编码到db中,因为这不会显示从一个应用程序到另一个应用程序再返回的真实数据流.感谢您的帮助.

I am looking to avoid hard coding sample data into the db in order to test the Universal app, as this would not show the true flow of data from one app to another and back again. Any help is appreciated.

更新8-21-2015:

我们意识到,由于框架的不同,最好的解决方案是运行某种类型的有序测试.我们正在使用MSTest.这样做的问题是Visual Studios中的有序测试不是解决方案范围广泛的,仅在单元测试项目中允许使用它们,这意味着它将使用该项目中的引用",而不允许同时进行这两种测试.

We realize because of the Framework difference the best solution is going to be to run some type of ordered test. We are using MSTest. The problem with this is that Ordered Tests in Visual Studios are not solution wide, they are only allowed in a unit test project, which means it will be using the References from that project, and not allow both tests.

我们不在乎是否必须切换到其他测试框架,因为拥有适当的测试比使用特定的框架更为重要.

We don't care if we have to switch to a different testing framework, as having the proper tests is more important than using a specific framework.

推荐答案

您应该使用可移植类库(PCL).您可以从添加新项目"屏幕在Visual Studio中创建PCL.

You should use a Portable Class Library (PCL). You can create a PCL in Visual Studio from the add new project screen.

在创建PCL时,它将询问您要定位的项目类型.既然您说过WPF和Windows Store应用程序,那么您将使用.Net 4.5(或您使用的任何版本)和Windows 8.1(或8.0)

When creating your PCL it will ask you what type of projects you want to target. Since you stated WPF and Windows Store app you would .Net 4.5(or whatever version you are on) and WIndows 8.1 (or 8.0)

PCL允许您在运行时以最低级别的语言功能为目标项目编写代码.在您的情况下,这将是Window的Store应用.

The PCL will allow you to write code in the Run Time with the lowest level of language features for the targeted projects. In your case this would be the Window's Store app.

现在,您需要将逻辑移到PCL中,而不是将逻辑存储在Window的store项目中.

Now, instead of storing your logic inside your Window's store project, you will need to move your logic into the PCL.

编译PCL之后,您将需要添加对Window的Store应用程序的引用,以便可以在Windows Store App中使用逻辑(必须添加PCL的命名空间才能使此工作正常进行).您还将在单元测试项目中添加对PCL的引用.因为您在PCL中都指定了两个运行时间,所以您可以从集成测试中调用代码.

Once you have compiled your PCL, you will need to add references to the Window's Store app so that you can use the logic within you Windows Store App (you will have to add the namespace for the PCL to make this work). You will also add a reference to the PCL in your unit test project. Because you targeted both Run times in your PCL, you will be able to call the code from your integration tests.

由于所有逻辑都在PCL中,因此您应该能够测试所有内容.现在,Window的商店"应用程序中唯一的内容应该是视图特定的数据.

Since all your Logic is in the PCL, you should be able to test everything. The only thing in your Window's Store app now should be the view specific data.

如果您需要更改PCL的目标(假设要使其与Windows Phone一起使用),则可以编辑PCL项目的属性,并更改目标.请注意,如果添加的目标的运行时间比当前选择的目标更严格,则必须重构代码以仅使用功能运行时间最短的功能.

If you ever need to change the targets for your PCL (lets say want it to work with Windows Phone), you can edit the properties of the PCL project, and change the targets. Be warned that if you add a target with a more constricted run time than one you currently selected, you will have to refactor your code to use only functions available in the lowest functional run time.

这篇关于在Visual Studio中使用不同项目类型进行集成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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