Sitelet https://github.com/microsoft/testfx/pull/5297
Skip to content

Allow async test methods for UITestMethod on UWP and WinUI - #5297

Merged
Youssef Fahmy (Youssef1313) merged 18 commits into
microsoft:mainfrom
Youssef1313:uwp-deadlock
Mar 31, 2025
Merged

Youssef Fahmy (Youssef1313) merged 18 commits into
microsoft:mainfrom
Youssef1313:uwp-deadlock

Conversation

@Youssef1313

@Youssef1313 Youssef Fahmy (Youssef1313) commented Mar 22, 2025 •

Copy link
Copy Markdown
Member

Fixes #5306

@microsoft-github-policy-service microsoft-github-policy-service Bot added area/uwp Universal Windows Platform support. area/winui WinUI support. labels Mar 22, 2025
Comment thread src/Adapter/MSTest.TestAdapter/Execution/TestMethodInfo.cs Outdated
Comment thread src/Adapter/MSTest.TestAdapter/Execution/TestMethodInfo.cs Outdated
Comment thread samples/Playground/Tests.cs
@marcelwgn

Copy link
Copy Markdown

Uhm, how does this address #740? The former is about being able to use datarows with UITests, this PR on the other hand allows using async on tests right?

@Youssef1313

Youssef Fahmy (Youssef1313) commented Mar 24, 2025 •

Copy link
Copy Markdown
Member Author

Marcel W. (@marcelwgn) The original issue description is inaccurate. Based on the comments/discussions there, the real issue is really just UITestMethodAttribute deadlocking. Using parameterized tests does not require DataTestMethodAttribute, and so we should not introduce UIDataTestMethodAttribute as it doesn't serve any purpose.

@marcelwgn

Copy link
Copy Markdown

So the following test should work then?

[UITestMethod]
[DataRow(0)]
[DataRow(1)]
[DataRow(2)]
public void TestMethod2(int index)
{
    var grid = new Grid
    {
        MinWidth = index
    };

    grid.UpdateLayout();

    Assert.AreEqual(index, grid.ActualWidth);
}

Because when I run it in Visual Studio, I get the following issue:

    Cannot run test method 'App8.UnitTest1.TestMethod2': Test data doesn't match method parameters. Either the count or types are different.
Test expected 1 parameter(s), with types 'Int32',
but received 0 argument(s), with types ''.

The thread in that issue evolved to providing a workaround to that missing capability using async tests that would essentially implement the behaviour that UITestMethod should support, but that requires async which is not supported. I disagree that the original issue description is misleading, the above sample does not work so there still is no support for this. ALlowing async would just allow for a workaround to work.

@Youssef1313

Copy link
Copy Markdown
Member Author

It's supposed to work. I'll check why it doesn't work, but that wasn't what I understood from the follow-up comments.

@Youssef1313

Copy link
Copy Markdown
Member Author

Marcel W. (@marcelwgn) This should be working if you are using the latest MSTest. I could repro only with really old versions of MSTest that are not supported.

@Youssef1313 Youssef Fahmy (Youssef1313) changed the title Add TestMethodAttribute.ExecuteAsync Allow async test methods for UITestMethod on UWP and WinUI Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/uwp Universal Windows Platform support. area/winui WinUI support.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support async test methods for UITestMethodAttribute (for UWP/WinUI)

3 participants