Skip to content

[Testing] Unify Test App infrastructure + VisualUITestBase #124

@michael-hawker

Description

@michael-hawker

Problem

We want our unit tests to not just be able to test .NET code, but also be able to exercise the UI to the extent possible in the UWP/WinUI test app scenarios.

Existing Solution

In the toolkit, we have a helper class called VisualUITestBase which allows a developer writing a unit test with UITestMethod to set the content of the test app temporarily in order to exercise a component, check its layout, and test other parts which may be required for the control to be visualized.

New Solutions

  1. Currently a lot of these tests use XamlReader to load XAML from code-behind to create their scenarios. This is a bit cumbersome, especially without the upcoming raw C# string literals. I'd like to investigate using an attribute style solution like we did for the Toolkit UI tests, so loose XAML files can be used to load test scenarios directly within the application.
  2. Once we reach this point, we get pretty close to being able to do more complex UI testing, it'd be great if we could try and bridge the complexity gap of the UI Testing systems that are really hard to work with on automation APIs and connecting test runners and the test hosting apps (and being able to run those in the CI across multiple automation framework technologies)... to instead just build on what we know works easily in the unit test structure that exists with MSTest and see if we can provide some basic UI manipulation helpers in order to test more complex scenarios.

Proposal Breakdown

  • Independent: Rename CommunityToolkit.Labs.Shared project to CommunityToolkit.Labs.SampleApp.Shared
  • Create a new common\Communitytoolkit.Labs.UnitTests.Shared shared project (to appear under the Shared Solution folder)
    • Add this to the root test heads
    • Remove all App.xaml/UnitTestApp.xaml and MainWindow.xaml files from unit test heads
    • Centralize on CommunityToolkit.Labs.UnitTests namespace
    • Use a common App.xaml file to include WinUI 2 and WinUI 3 for all the test heads (just like the individual platform heads do)
    • Abstract the startup for UWP vs. WinUI 3 (see project heads shared App.xaml.cs file)
    • Make sure WINAPPSDK conditional works the same for unit test projects
  • Add VisualUITestBase class from Toolkit version
    • Add the new shared unit test project to the experiment shared projects
    • Add 7.1.2 Toolkit references for UWP/WinUI 3 for Visual Tree helpers and the like
  • New VisualUITestBase improvements - handled by API Spec for Reunion Deployment Information API microsoft/WindowsAppSDK#156 now
    • Add ability to lookup attribute in TestInitialize in base class
    • Load from page in shared experiment project
    • Auto Dispatch? (all these UI tests had to dispatch to the UI thread to load, so we can automatically handle that I think?).
  • Test works in all environments:
    • UWP/WinUI 3 with all solution
    • UWP/WinUI with experiment solution
    • CI
  • Investigate helper methods for more 'ui testing' scenarios
    • Since we own the apps and their deployment can we use more restricted capabilities like the InputInjection rescap? And does that work in WinUI 3 as well?
    • Does this work in the CI?
  • Use GridSplitter as a test case and see if we can:
    • [ ]~ Test Localization (will be good test for UWP/WinUI 3 and resource loading)~
    • Test a mouse drag (if we get injector working) replicate the UI Test we had for GridSplitter

Metadata

Metadata

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions