Since the last update, we now have the possibility to use Universal Apps to share code between a Windows Phone and the Store App. From a technical point of view, there are three projects involved when you create a universal app: The phone application, the store application and a shared code projects. The shared code project is not an assembly as we know from portable libraries.The shared code project copies the source file to the project from which it is being referenced.“

There are two scenarios which could limit the testing possibilities or lead to code duplication:

  • If there is code which in the shared code project which should be unit tested.
  • If we need to run integration tests in the context of the store or phone app.

For the first issue, we could simply create a portable or universal library and create a unit test project which references it. If this is not possible or if we need to run integration tests, we need a possibility to write the test code once and use it for both types of applications. We could expect that this is as easy as creating a universal app, but there is no possibility to create shared code projects by default.

There is a small Visual Studio Extension called “Shared Project Reference Manager”. It provides the functionality to create a shared project and also to add a shared project reference to any project in the solution.

image

We now need a test project for the phone and store app.

image

Now we create a shared project which will hold our testing code:

image

And finally, we need a shared project reference from the two testing projects to our shared project:

image

At the end we have a solution which duplicates the integration tests by copying the test source files to the testing project during compile time.

image

No Comments