Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

Migrates tests from [TestMethod] with EnqueueAsync to [UIThreadTestMethod] pattern, adding explicit composition rendering waits for property propagation. This addresses CI failures on .NET Native UWP builds.

Tests Converted

  1. ShouldConfigureGridSplitterAutomationPeer (ExampleSizerBaseTestClass.cs)

    • Replaced [TestMethod] + EnqueueAsync wrapper with [UIThreadTestMethod]
    • Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after gridSplitter.Name and gridSplitter.SetValue() calls to ensure property changes propagate before assertions
  2. ComplexAsyncLoadUIExampleTest (ExampleColorPickerTestClass.cs)

    • Replaced [TestMethod] + EnqueueAsync wrapper with [UIThreadTestMethod]
    • Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after LoadTestContentAsync and UnloadTestContentAsync to ensure UI updates complete before assertions

Before/After

// Before
[TestMethod]
public async Task TestName()
{
    await EnqueueAsync(async () =>
    {
        await SomeUIOperation();
        // assertions
    });
}

// After
[UIThreadTestMethod]
public async Task TestName()
{
    await SomeUIOperation();
    await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
    // assertions
}

Pattern matches existing usage across 15+ test files in the codebase.

[!WARNING]

Original prompt

Convert the test ShouldConfigureGridSplitterAutomationPeer in components/Sizers/tests/ExampleSizerBaseTestClass.cs to use [UIThreadTestMethod] instead of [TestMethod] and remove usage of EnqueueAsync. After each assignment to gridSplitter.Name and gridSplitter.SetValue, add the line:
await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
This ensures test logic waits for property propagation before asserting. The test framework must support [UIThreadTestMethod].

Summary of changes:

  • Use [UIThreadTestMethod] on the test method and remove EnqueueAsync wrapper.
  • After setting gridSplitter.Name and gridSplitter.SetValue, insert await CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync(() => { });
  • Do not reference any GitHub issue in the PR, as per team direction and repository policy.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@michael-hawker michael-hawker marked this pull request as ready for review December 19, 2025 20:18
Copilot AI changed the title [WIP] Convert ShouldConfigureGridSplitterAutomationPeer to use UIThreadTestMethod Convert ShouldConfigureGridSplitterAutomationPeer test to UIThreadTestMethod Dec 19, 2025
Copilot AI requested a review from michael-hawker December 19, 2025 20:24
Copilot AI and others added 2 commits December 19, 2025 14:49
…tMethod

- Changed [TestMethod] to [UIThreadTestMethod]
- Removed EnqueueAsync wrapper
- Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after gridSplitter.Name assignment
- Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after gridSplitter.SetValue call
- Added using CommunityToolkit.WinUI.Helpers for CompositionTargetHelper

Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
@michael-hawker michael-hawker force-pushed the copilot/convert-test-to-ui-thread-method branch from 97f6180 to 55b3ecf Compare December 19, 2025 22:49
@michael-hawker
Copy link
Member

Updated to run it again will see if it passes again or if fluke. If this does make a different then it at least gives us some insight that it could be this specific test pattern that somehow has issues... FYI @Arlodotexe

@michael-hawker
Copy link
Member

(UWP CI fail on .NET Native)

@michael-hawker
Copy link
Member

ColorPickerTests.ExampleColorPickerTestClass.ComplexAsyncLoadUIExampleTest is another one failing and uses the same pattern.

@michael-hawker
Copy link
Member

@copilot apply the same [UIThreadTestMethod] fix to the ColorPickerTests.ExampleColorPickerTestClass.ComplexAsyncLoadUIExampleTest test in this same PR.

- Changed [TestMethod] to [UIThreadTestMethod]
- Removed EnqueueAsync wrapper
- Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after LoadTestContentAsync
- Added CompositionTargetHelper.ExecuteAfterCompositionRenderingAsync() after UnloadTestContentAsync
- Added using CommunityToolkit.WinUI.Helpers for CompositionTargetHelper

Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 20, 2025

@copilot apply the same [UIThreadTestMethod] fix to the ColorPickerTests.ExampleColorPickerTestClass.ComplexAsyncLoadUIExampleTest test in this same PR.

Applied the same fix to ComplexAsyncLoadUIExampleTest. The test now uses [UIThreadTestMethod] instead of [TestMethod] with EnqueueAsync, and includes composition rendering waits after LoadTestContentAsync and UnloadTestContentAsync to ensure UI updates complete before assertions. Changes in commit b6da782.

The using CommunityToolkit.WinUI.Helpers is not needed as CompositionTargetHelper is already available through the test base class.

Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Copilot AI changed the title Convert ShouldConfigureGridSplitterAutomationPeer test to UIThreadTestMethod Convert tests to UIThreadTestMethod pattern Dec 20, 2025
@michael-hawker michael-hawker merged commit d30f407 into main Dec 22, 2025
23 checks passed
@michael-hawker michael-hawker deleted the copilot/convert-test-to-ui-thread-method branch December 22, 2025 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants