-
Notifications
You must be signed in to change notification settings - Fork 269
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WinUI3 Test App UITestMethod failing #5175
Comments
The error mentions this:
Did you do that? If yes, can you upload a project that reproduces this? |
The empty test project does this in the UnitTestApp.xaml.cs /// <summary>
/// Invoked when the application is launched.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.CreateDefaultUI();
m_window = new UnitTestAppWindow();
m_window.Activate();
UITestMethodAttribute.DispatcherQueue = m_window.DispatcherQueue;
Microsoft.VisualStudio.TestPlatform.TestExecutor.UnitTestClient.Run(Environment.CommandLine);
} |
@DavidTynewyddBI
|
I confirm that |
@Evangelink I know this has been asked before, but is there any plan for support on the horizon? It seems strange to me that the two are incompatible |
@nohwnd Should this move to VSTest as a feature request? Or maybe track one item for VSTest (if you want to), and one other item for MTP? |
VSTest is not adding new features, and the limitation is coming from how the bits that test uwp and winui are shipped (as far as I am aware). The two special pieces that VisualStudio has (and that vstest.console.exe that is shipped WITH visual studio has), are UWP test runtime provider and uwp deployer. They depend on deployment tooling in VS and are under VS license. So unless we extract the tools, review their licensing and start shipping the provider and deployer with Microsoft.TestPlatform vstest.console and dotnet test vstest.console we will not have the functionality outside of VS shipment. I did not look if all the things that are needed are closed, or maybe already shipped to nuget.org, we can have a look for MTP where we might need it to bring the feature. |
Thanks for the quick responses all. My main reason for trying to use |
I do agree with you. One thing I can recommend is running your desired dotnet test command with --diag:log.txt, and grabbing the runsettings xml from there, you will need to remove the concrete paths for data collectors, but overall that should give you a full and portable way of using the same setup among dotnet test and vstest.console. |
Describe the bug
When trying to run tests from a WinUI3 test app, getting the following for tests marked with the [UITestMethod] attribute:
Failed TestMethod2 Error Message: An unhandled exception was thrown by the 'Execute' method. Please report this error to the author of the attribute 'Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute'. System.InvalidOperationException: UITestMethodAttribute.DispatcherQueue should not be null. To use UITestMethodAttribute within a WinUI Desktop App, remember to set the static UITestMethodAttribute.DispatcherQueue during the test initialization. at Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.Execute(ITestMethod testMethod) in /_/src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:line 67 at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.ExecuteTest(TestMethodInfo testMethodInfo) in /_/src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs:line 460
Works fine if run within Visual Studio's test explorer.
Steps To Reproduce
dotnet build
dotnet test .\bin\Debug\net8.0-windows10.0.19041.0\win-x64\App1.dll
(replace with your app name)Expected behavior
The two default tests to pass
Actual behavior
The test marked with
[UITestMethod]
fails with:Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Failed TestMethod2
Error Message:
An unhandled exception was thrown by the 'Execute' method. Please report this error to the author of the attribute 'Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute'.
System.InvalidOperationException: UITestMethodAttribute.DispatcherQueue should not be null. To use UITestMethodAttribute within a WinUI Desktop App, remember to set the static UITestMethodAttribute.DispatcherQueue during the test initialization.
at Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.Execute(ITestMethod testMethod) in //src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs:line 67
at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestMethodRunner.ExecuteTest(TestMethodInfo testMethodInfo) in //src/Adapter/MSTest.TestAdapter/Execution/TestMethodRunner.cs:line 460
Failed! - Failed: 1, Passed: 1, Skipped: 0, Total: 2, Duration: 115 ms - App1.dll (net8.0)
Additional context
I'm unclear if this should even work at this point. I found some old references saying it wasn't supported, but the most recent was a year ago.
The text was updated successfully, but these errors were encountered: