question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to create unit tests for a project that sets `XamlControlsResources`

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
kmahonecommented, Feb 1, 2019

I’ve filed an internal issue to track this.

1reaction
kmahonecommented, Jan 28, 2019

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found