microsoft-ui-xaml: Unable to create unit tests for a project that sets `XamlControlsResources`

Describe 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:

  1. Create a new, blank UWP app image
  2. Set the target framework to be 1809 image
  3. Add a Unit Test App (Windows Universal) app to the solution and set the same target/min framework versions as the app. image
  4. Add a reference in the test app that points to the blank app.
  5. Run the default test “TestMethod1”. It will pass. image
  6. 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.
  7. Run the unit test again. It will still pass.
  8. In App.xaml in the blank project, add the required reference to XamlControlsResources.
    <Application.Resources>
        <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls"/>
    </Application.Resources>
  1. 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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 3
  • Comments: 16 (11 by maintainers)

Commits related to this issue

Most upvoted comments

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.