Hi,
if a Universal Windows project uses the Prism and Prism.Windows it's not possible to get a unit test project (Universal Windows) running, it crashes immediately with the error:
Cannot deserialize XBF metadata type list as 'PrismApplication' was not found in namespace 'Prism.Windows'. [Line: 0 Position: 0]
It's easy to reproduce:
Open PrismLibrary_Win10.sln.
Add a new "Blank App (Universal Windows) project
Add references to Prism and Prism.Windows
Change App.cs and App.xaml:
public sealed partial class App : PrismApplication
{
protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
{
throw new NotImplementedException();
}
}
<prism:PrismApplication
x:Class="App1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:prism="using:Prism.Windows"
xmlns:local="using:NewsgroupsRT"
RequestedTheme="Dark"
>
</prism:PrismApplication>
Add a new "Unit Test App (Universal Windows)" project
Add references to App, Prism and Prism.Windows
Run the unit test project.
How can I fix this?
Thanks
I usually only keep view related things in the Windows project and everything else (including converters, viewmodels ...) in a class library which is then referenced in the test project. Do you get the error with this approach as well?
The error only occurs if the Prism.Windows project must be referenced by the test project. So if you want to test ViewModels you need the Prism.Windows stuff because ViewModelBase is a part of it. So the answer is yes I get the error with this approach as well because I'm testing my ViewModels.
Is this a known issue or am I the only one who has this problem?
I had the same error so I take the same approach as bartlannoeye : only views in my store project and all other stuff in a library
I can make unit tests of universal projects but not with Prism referenced.
I have already noticed before that a UWP test project is very fragile, even worse than it was on Windows 8/8.1. And being unable to run your tests with R# (9.1.3) doesn't help a lot either.
I'm able to run the tests from the class library on my test branch, even when using Prism and Prism.Windows. I'll extract this fix to the main branch.
I'm not able yet to reference the app itself to test it, and to be honest I'm hesitant that this was even possible in Windows 8.1 (I have never done it). How do you get the XBF error? Did you enable local crash dumps for that as that's the only message my VS test runner provides me when failing at this point.
Yeah, in fact with the current Prism.Windows.Tests project, if I try to Run All in Test Explorer, VS just kind of goes in limbo and never starts any of the tests. But if I select all tests and right click and run all, they run fine. Would love to figure out what is going on there, but for now as long as the tests run somehow I haven't had the bandwidth to try to figure out if it is a bug with VS, the platform, or something weird about our test project. I even tried creating a new Windows 10 UWP project and test project on my machine and the same happens for me for the out of the box project templates, so not thinking it is really our code that has the issue. And I've tried on all three of my machines with same results.
Sorry I'm not completely sure what's happening here. As far as I understand the exception, XBF files are binary representatives of XAML files, my example to reproduce the error includes only one XAML file which is possible to be responsible for the error:
App.xaml of the Blank App project.
So with high probability the problem is in the PrismApplication.cs ... so I guess the only solution to gather more information about this issue is to delete line after line in PrismApplication.cs until the exception disappears.
Currently I'm running low on time, but I think at the weekend I can take a closer look, maybe I can provide some more information.
I've had the XBF error before when doing Win8.1 dev because the library project was missing XAML files and therefore no .xbf file was being generated. I've tried adding a XAML file, but this doesn't make tests run. For now I'd say use a separate library for all you code and make sure the build configuration is x86 for all assemblies to make sure your tests run.
Hmmmmm
Hello everyone.
If you moved your ViewModels from a Windows Universal App to a Windows Universal Class library, would it cause a lot of harm? because now the test looks like it can run without problem.
Not exactly a solution, of course.
If your ViewModels inherit from ViewModelBase it's not possible ;)
@diego2k Why is it not possible. You can definitely define ViewModels in a Windows Universal Class Library project, derive from ViewModelBase, add a Windows unit test project to the solution and test it from there, just did it.
That's exactly what I did @diego2k in my test branch: https://github.com/bartlannoeye/Prism/tree/140_UnitTest?files=1
Be sure your configuration is x86 for all projects as UWP doesn't have AnyCPU.
Hm that's interesting, @bartlannoeye yes your example works. So this means Prism and Prism.Windows must be referenced by a Blank App (Universal WIndows) project and die Blank App must be referenced by a Unit Test App (Universal Windows) project. If it is a Class Library (Universal Windows) instead of a Blank App everything works.
Tried to reproduce the same behavior but without Prism at all.
1.- Created a UWP App. Named: MyAwesomeApp (of course)
2.- Created a UWP Lib. Named: MyAwesomeLib
3.- Inside MyAwesomeLib, created a new class. Name: AwesomeApplication. Inherits from Application. NO CODE AT ALL
4.- Inside MyAwesomeApp, Reference MyAwesomeLib and, change the base class of App.xaml (and cs) to AwesomeApplication
5.- Created a UWP Unit Test Project. Named: MyAwesomeApp.Test
6.- Inside MyAwesomeApp.Test, reference both MyAwesomeApp and MyAwesomeLib
7.- Run the test. The exception thrown is:
"Cannot deserialize XBF metadata type list as 'AwesomeApplication' was not found in namespace 'MyAwesomeLib'. [Line: 0 Position: 0]"
So I guess there is nothing wrong with Prism.Windows itself, and it's more something about UWP Unit Tests not referencing UWP Apps.
Have to investigate more. Anyway, there is at least a workaround
If you add the [Bindable] attribute to the application class, does it still error?
@brianlagunas I think the conclusion of this issue according to @TioLuiso and my tests is that you can't reference a UWP app into a unit test project. It has nothing to do with Prism. Code that you want to be tested should be in a class library.
You cannot unit test a UWP project, only a class library (at this time).
@JerryNixon thanks for validating the state of UWP testing
This article confirms that Coded UI Testing for Windows Store is supported.
https://msdn.microsoft.com/en-us/library/dn305948.aspx
This article infers that Coded UI Testing for UWP is still forthcoming.
https://blogs.msdn.microsoft.com/visualstudioalm/2016/03/10/visual-studio-team-services-testing-tools-roadmap/
@JerryNixon well that's not confusing :)
Just wanted to check-in with the current status. Last update was December last year.
The first links goes to docs for 8.1 apps, not UWP. I've used Coded UI on 8.1 in the past (iirc) so that's right. So I suppose we can conclude it's still a no-go.
Just to add some additional info: Even with [Bindable], you will still get a Catastrophic Failure exception if you try to debug your unit tests. However, although the Catastrophic Failure exception is thrown, it is not fatal. In fact, if you turn off 'Break when this exception type is user-unhandled', the unit test app will continue to run and the tests can be debugged as normal (and the test runner does not hang and can be re-ran without relaunching VS). Any code in the app-under-test's constructor does not get executed due to the exception, but this at least helped me debug some tests that were self-contained. Still not sure of the root cause (I know the Prism team said that UWP testing in this manner is not supported at the moment, but VS does support it and it works for apps that dont use a custom Application class, so there must be some way to get it to work).
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
You cannot unit test a UWP project, only a class library (at this time).