Integration Testing In Visual Studio With Differen

2019-05-10 19:04发布

问题:

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. Customer calls in and gets scheduled on a field user in WPF app.
  2. Field user goes on service call and updates on Surface through Universal App.
  3. Customer gets billed from the WPF App.

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.

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.

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.

UPDATE 8-21-2015:

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.

回答1:

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

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)

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.

Now, instead of storing your logic inside your Window's store project, you will need to move your logic into the 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.

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.

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.