Unable to create unit tests for a project that sets `XamlControlsResources`
See original GitHub issueDescribe the bug
Setting XamlControlsResources
as a resource in an app means the app can’t be tested with a Unit Test App (Windows Universal)
app.
Steps to reproduce the bug
Steps to reproduce the behavior:
- Create a new, blank UWP app
- Set the target framework to be 1809
- Add a
Unit Test App (Windows Universal)
app to the solution and set the same target/min framework versions as the app. - Add a reference in the test app that points to the blank app.
- Run the default test “TestMethod1”. It will pass.
- In both apps, add a reference to
Micrsoft.UI.XAML
(version 2.0.181018003.1). The test project will raise a warning if it doesn’t have the reference but will still work without it. - Run the unit test again. It will still pass.
- In
App.xaml
in the blank project, add the required reference toXamlControlsResources
.
<Application.Resources>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
</Application.Resources>
- Run the unit test again.
Expected behavior Expect the test to pass.
Actual behavior The test doesn’t even run. The status bar states “Unexpected error detected.”
From the test output pane:
[1/28/2019 2:35:31 PM Informational] ------ Run test started ------
[1/28/2019 2:35:44 PM Error] Failed to initialize client proxy: could not connect to test process.
[1/28/2019 2:35:44 PM Error] Failed to initialize client proxy: could not connect to test process.
[1/28/2019 2:35:44 PM Informational] ========== Run test finished: 0 run (0:00:12.429535) ==========
Version Info
Windows 10, Version 1803 (17134.523) VS 2017 15.9.6
NuGet package version: Microsoft.UI.Xaml 2.0.181018003.1
Windows 10 version | Saw the problem? |
---|---|
Insider Build (xxxxx) | |
October 2018 Update (17763) | |
April 2018 Update (17134) | Yes |
Fall Creators Update (16299) | |
Creators Update (15063) | |
Anniversary Update (14393) |
Device form factor | Saw the problem? |
---|---|
Desktop | Yes |
Mobile | |
Xbox | |
Surface Hub | |
IoT |
Additional context
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:16 (11 by maintainers)
Top Results From Across the Web
Unable to create unit tests for a project that sets ...
Setting XamlControlsResources as a resource in an app means the app can't be tested with a Unit Test App (Windows Universal) app. Steps...
Read more >WPF project - unable to set up unit testing (C#)
I'm attempting to set up unit tests for a WPF project I have. I have a public method called MoveSelectionOutOfSelectedBox in a project...
Read more >can not create unit test project c# - Developer Community
I just tried creating a new empty solution from File -> New -> Project -> other project types -> Visual Studio solution and...
Read more >Get started with unit testing - Visual Studio (Windows)
Create unit tests. This section describes how to create a unit test project. Open the project that you want to test in Visual...
Read more >Live Unit Testing FAQ - Visual Studio (Windows)
Review these Live Unit Testing frequently asked questions, including supported frameworks, configuration, and customization.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve filed an internal issue to track this.
I took a look at this issue.
The problem is that the Unit Test project does not generate an IXamlMetadateProvider, so when the runtime tries to get the Xaml metadata for XamlControlsResources, it fails.
It is possible to workaround this issue by forcing the Unit Test project to generate an IXMP, e.g. by adding a reference to a dummy custom type into UnitTestApp.xaml
<Style TargetType="local:MyButton" />
public class MyButton : Windows.UI.Xaml.Controls.Button { }
I need to figure out why the Unit Test Project is not generating IXMP.