0

I'm developing a WPF application and I'm using Xaml Islands to display win10 UI components. For this I needed to create a UWP project where I can implement those components.

I'd like to write unit tests for my business logic, which is in the WPF project. I can't create a Unit Test App (Universal Windows), because it's not possible to add as a reference to this project the WPF app. So I tried to create a testing project, which targets .NET Core (tried MSTest Project and xUnit Test Project), but as I add to the references my WPF app, it shows the following error:

Project <UWP...> is not compatible with netcoreapp3.1 (.NETCoreApp,Version=v3.1). Project <UWP...> supports: uap10.0.18362 (UAP,Version=v10.0.18362)

This is because the WPF app references the UWP app, to display the win10 components.

So, any idea, how can I add unit testing project to my solution?

Attila Szász
  • 707
  • 4
  • 22
  • 1
    What about moving your business logic to a dedicated assembly targeting .NET Standard? – mu88 Feb 25 '21 at 15:30

1 Answers1

0

So, any idea, how can I add unit testing project to my solution?

There is a design pattern called Model-View-ViewModel (MVVM) which is the recommended design pattern for developing XAML based UI applications. If you are serious about developing UI applications on Windows using XAML, you should really learn it.

One of the main benefits of adopting it, besides the separatation of concerns it brings, is testability. The idea is that you write your application logic in view models that can easily be unit tested in isolation from the rest of the application.

Using this approach, could implement your view model classes in a class library that has little or no dependency upon the WPF or UWP assemblies and then simply add a reference to this class library from your test project as usual.

mm8
  • 163,881
  • 10
  • 57
  • 88
  • Thanks for the hint. I'm already using the MVVM pattern, but it would be a huge effort and work to move out the business logic to another project – Attila Szász Feb 26 '21 at 14:44
  • @AttilaSzász: It shouldn't be really. Also note that the business logic belongs to the model in MVVM. – mm8 Feb 26 '21 at 17:14