-
Notifications
You must be signed in to change notification settings - Fork 243
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
WinUI 3 Tests fail to run after upgrade to Windows App SDK 1.1 #1127
Comments
@Haplois Isn't this something you handled recently? |
@Marv51 I'm experiencing the same issue |
Hi all, I have the same problem too. In my case it seems that the App class is not instantiated when running the tests. For this reason I cannot update my projects to 1.1.3. Thank you, |
It appears that when switching from 1.0.X to 1.1.X, the call to the Win32 API function
APPMODEL_ERROR_NO_PACKAGE . As a result, when Test Explorer loads the assembly, in 1.0.X builds it finds IsAppContainer: True but in 1.1.X IsAppContainer: False.
I'm not sure why it's doing this, but it does indeed not have any packaging information after the switch. In a 1.0.X build, a test marked Without Also, just as a debugging note, if you switch a project from WindowsAppSDK 1.0.X to 1.1.X, you will probably need to do a rebuild to see the errors; for me if I just switched and did a regular build, it would still launch the app and appear to work correctly (leading to a false hope that I had figured out a work-around). I tried using a local build of MSTest (using the rel-2.2.10 branch) and changing it to use WindowsAppSDK 1.1.0 (and 1.1.3) instead of 1.0.0, but it did not change the results in any way. The code at
Microsoft.WindowsAppSDK.Runtime.Identity , is not found in either 1.0.X or 1.1.X. It just returns null so no instance of a type is ever created to trigger SDK initialization. I was unable to find a good replacement to test that with.
My test project is essentially the same as the original bug report. |
Some updated information. I was able to partially workaround this by turning the app into an unpackaged app in order to be able to initialize the WindowsAppSDK and then start the app, as described below. For reasons I put at the end, I don't feel that this workaround is a viable long-term solution, but it might help some people for now. Note: I used the MSTest 2.2.10 packages and WinApp SDK 1.1.3. Here is what I did: I changed my test project to be explicitly unpackaged and to not automatically load WinAppSDK by adding I then created a local copy of I set the entry point using Lastly, I changed my I then ran the tests and the application launched properly and was able to run UI tests such as verifying an element's existence using its AutomationId. Unfortunately, this is not a good workaround for any long-term purposes. If you have anything in your App (UI or otherwise) that directly or indirectly requires a package identity, this will not work for you unless you went through the effort of creating a sparse package just for UI testing purposes. Outside of this workaround, the apps are being built into MSIX packages and thus automatically have identity without that. You need to make sure you download and run the appropriate WindowsAppSDK runtime installer (or setup your testing app to do bootstrapping to install it). It's important to do this because you probably won't have the Microsoft.WinAppRuntime.DDLM packages installed. They are only necessary for unpackaged apps since they are responsible for "pinning" the runtime that your app is using to make sure it isn't upgraded or otherwise changed while your app is running. That package together with the Lastly, you need to make sure to update the versioning data in Regardless, it is a workaround that may be helpful to some people until this problem is resolved so I figured I would add it here. To me its main value is showing that it is possible to use MSTest to test apps that use WindowsAppSDK 1.1 (since it will properly launch the app and run tests against the UI as long as you go through with all of the steps needed to have it be unpackaged so you can get the runtime to actually initialize and start your app). The root problem is that (for some reason I haven't discovered), Windows reports DLLs from an app packaged with SDK 1.1 as not having package identity whereas with SDK 1.0 they are reported as having package identity. MSTest relies on that identification of having package identity to properly launch WinUI packaged apps for testing and so if you update an app to SDK 1.1 (without any other changes), testing stops working. |
I am also having this issue as mikebmcl is describing. Unfortunately that workaround does not work for me because it creates issues with the SDK. I hope this gets fixed soon because I have no choice besides using 1.1.0 so I can't downgrade to 1.0.x to gain use of the UITestMethod. |
From what I can tell, MSTest.TestFramework still has bugs relevant to this (described below) but the problem that starts everything off does not originate with MSTest.TestAdapter. Its I'm attaching a repro project. In addition to Debug and Release configurations, it also has Test10 and Test11 configurations. When using x86, those will expose the tests and swap between WindowsAppSDK 1.0.4 (Test10) and 1.1.3 (Test11). In any other configuration the SDK is 1.1.3. The PackageReference to the correct SDK for the configuration is included using conditional ItemGroup markup in the .csproj file. Because of this, Solution Explorer will not always show the correct value for the SDK package version that is currently being used. It doesn't seem to expect that different versions of a nuget package will be conditionally included. But as long as you do a Rebuild after switching configurations before attempting to run the tests, the proper SDK package will be used. The If If Ultimately, This was all tested using Windows 11 Pro 10.0.22622 Build 22622 with Visual Studio 2022 Community Version 17.3 Preview 5.0. Hopefully you can file an internal ticket about the |
Just a small message to let you know that we have seen this ticket and we will handle as fast as we can (we are a little short staffed with holidays and some other high priority tasks we need to handle). |
Just as a note, this might be the same problem as or closely related to this open issue in the WindowsAppSDK: |
Probably not, we invoked the |
I've found a better workaround (though still not optimal). It's better because you can keep your app packaged, but it is not optimal because you need to do the testing from a console rather than in Visual Studio and there are some potential pain points associated with that (described below). If you follow the instructions for "UWP Example" using VSTest.Console from the command line making sure to change Note that if you do try to run an x64 version, the app will launch but then no tests are run and it just sits there until you close the app and use Ctrl-C to terminate vstest.console.exe from the console. I don't think x64 testing was supported originally though, so I don't think this is actually a change. I also didn't spend any time trying to get it to work; I just ran it to see what would happen and that's what happened. The downsides are that you need to run it from the command line rather than directly in Visual Studio, and will need to either specify the test methods directly using the Test Filtering is a lot more practical if you have a lot of tests but note that some attributes, such as I ended up coming across this because the using Trace as the Logging Level in the Test settings in VS, I noticed that WinAppSDK 1.0 apps were getting a string value for Package in the TestRunCriteriaWithTests class (VSTest) which was the MyProject.build.appxrecipe file when running the tests whereas with SDK 1.1+, Package didn't appear in the output for "TestRequestHandler.OnMessageReceived: received message: (TestExecution.StartWithTests)" (presumably because it was null for the reason stated in the documentation of the Package property). I think this all ties back to ProjectOutputContainerDiscoverer determining that SDK 1.1+ projects are not app containers. It seems to do that by calling the IVsHierarchy.GetProperty method using VSHPROPID_AppContainer and VSConstants.VSITEMID.Root and interpreting the result as a The description for The more I dig into it, and I'm not sure I'm going to dig any further now that I have a workaround I can use, the more I'm convinced that it's a VSTest issue. One that can't be resolved for Test Explorer except by fixing it in the internal version that Test Explorer uses since VSTest has been built-in rather than an extension since Visual Studio 2019. If my guess about the discoverer determining that SDK 1.1 projects are not app containers are right, then it actually would come from some change to WindowsAppSDK that appeared in 1.1. Regardless, there are a lot more changes in the data of the My main purpose was to share the new workaround. I figured I'd also note down these insights I gained in the process of finding it in case they are of some help in finding and resolving the problem! |
Edit: Setting I solved the problem. What happened was that WindowsAppSDK stopped defining certain MSBuild properties beginning in version 1.1 that it defined in 1.0. There are also certain properties that changed. In total, there are four properties that need to be added to your .csproj now rather than the one property that the article mentions. Once these are added, if you followed the rest of the directions in the article you will be able to use MSTest with Test Explorer in Visual Studio (the same as before). I'm attaching the fixed version of the repro project I posted earlier. But here are the key properties that need to be in a
Making sure you have those The problem with the entire test run crashing if there's a COMException when trying to start the app still should probably be fixed, but I think that's an issue with VSTest. Either way, the above changes avoid that because the app will launch correctly and testing will work the same as was described in the original article! (Note: This is the updated version mentioned in the edit note at the top.) |
Really sorry for the super long delay folks... @mikebmcl I remember that the 1st time I tried your repro I was able to see the issue but I cannot repro anymore. We tried to create a new repro but all our tries failed. Would you mind sharing if you are still able to reproduce the issue? If so what are the conditions (same project listed above? what steps are you doing? Would you mind also sharing the result of I have pinged @mikebmcl but obviously we are interested in all your feedback about this issue. |
@Evangelink I do still encounter it when using MSTestWinAppSDK11BugRepro above with Test11|x86 configuration.
When using MSTestWinAppSDK11BugSolved above, which includes I found that sometimes VSTest will not pickup changes in the repro after changing the solution configuration just by doing a Rebuild. Instead I needed to do a Clean first followed by a Build or Rebuild. I think it's because of the conditional package inclusion in the .csproj that enables testing against WindowsAppSDK 1.0.X and 1.1.X versions. Tested with Visual Studio 2022 Community 17.3.6 on Windows 11 Pro 10.0.22623 Build 22623. |
Thank you! I will try to create a clean VM and see if I can repro because locally I can't :c
My runtimes are similar to yours (I don't have 1.2):
I have seen similar behavior. I am also ensuring that I uninstall app between builds (I am not super familiar with WinUI so I don't know if it could be messing up). |
I have managed to reproduce the issue consistently! I have tweaked a little your csproj (see below) so that I can test the various combinations of <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>MSTestWinAppSDK11BugRepro</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<PublishProfile>win10-$(Platform).pubxml</PublishProfile>
<UseWinUI>true</UseWinUI>
<Configurations>Debug;Release;Test10;Test11</Configurations>
<!--
For Test10 (x86 and x64), only the following property is required.
If property is not present, the tests won't run.
I couldn't test arm64:
DEP3308: Deployment target 'Local Machine' does not support projects targetting ARM64 platform. Supported platforms: X86,X64.
-->
<!--<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>-->
<!--
For Test11 (x86 and x64), a combination of WindowsAppContainer and
EnableMsixTooling OR EnablePreviewMsixTooling is required.
I couldn't test arm64:
DEP3308: Deployment target 'Local Machine' does not support projects targetting ARM64 platform. Supported platforms: X86,X64.
-->
<EnableMsixTooling>true</EnableMsixTooling>
<!--<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>-->
<WindowsAppContainer>true</WindowsAppContainer>
</PropertyGroup>
<ItemGroup>
<Content Include="Assets\SplashScreen.scale-200.png" />
<Content Include="Assets\LockScreenLogo.scale-200.png" />
<Content Include="Assets\Square150x150Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.scale-200.png" />
<Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
<Content Include="Assets\StoreLogo.png" />
<Content Include="Assets\Wide310x150Logo.scale-200.png" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.TestHost" Version="17.3.0">
<ExcludeAssets>build</ExcludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.1" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
<ItemGroup>
<ProjectCapability Include="TestContainer" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'=='Test10'">
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.4" />
</ItemGroup>
<ItemGroup Condition="'$(Configuration)'!='Test10'">
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.1.4" />
</ItemGroup>
<!--
Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
Tools extension to be activated for this project even if the Windows App SDK Nuget
package has not yet been restored.
-->
<ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<ProjectCapability Include="Msix" />
</ItemGroup>
<PropertyGroup>
<DefineConstants>TESTRUNNER</DefineConstants>
</PropertyGroup>
<!--
Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
Explorer "Package and Publish" context menu entry to be enabled for this project even if
the Windows App SDK Nuget package has not yet been restored.
-->
<PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
<HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
</PropertyGroup>
</Project> For Test10 (x86 and x64), the only way to have the test working (for me) was to add For Test11 (x86 and x64), the only way to have the test working (for me) was to have either <EnableMsixTooling>true</EnableMsixTooling>
<WindowsAppContainer>true</WindowsAppContainer> or <EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
<WindowsAppContainer>true</WindowsAppContainer> Could you confirm this is what you have on your side? Note that for I will start back discussion with WinUI team now that I have a consistent reproduceable scenario. |
That essentially matches what I have, yes. I define both
and
for all configurations. WindowsAppSDK 1.0 does not reference I too can only get I found that doing a Clean followed by Rebuild would display the correct behavior when switching to or from |
Just a quick message to say that we (with |
Hey there! We identified a root cause of this error and filled a Dev Community bug for a fix. We also identified some improvements on WinUI and MSTest sides and we also discussed a way to improve our testing matrix to reduce likelihood of such issue in the future. Thanks again for your patience. |
I will move forward by closing this issue as the fix won't be done in MSTest. As I said already, thank you all for your patience and the big investigation effort you did (special mention to @mikebmcl). |
* Moved project heads to common folder * Fixed broken reference to props file * Fix broken path references * Fixed broken file references * Fixed broken path * Move asset references to props file * Consolidated ProjectHeads and supporting infrastructure * Migrating projects to new infra * Migrating files to new infra * Added missing assemblyname and rootnamespace declaration * Fixed building WinAppSdk * Fixed build errors for UWP under "All" solution * Fixed working directory for UseTargetFrameworks.ps1 * Switch GenerateSingleSampleHeads.ps1 to use dotnet templating tool Update WindowsAppSDK version and MSTest tools Add properties to allow tests to run on 1.2.x, see microsoft/testfx#1127 Remove solution files from experiments Add bat file to copy heads and run slngen Tested locally running all heads and tests for an experiment * Update folder for linux CI build and Codespaces to WASM project * Clean-up and re-work build script for testing the project template * Use expanded form for environment variables everywhere * Use repo root path for script when in working directory of template * Use github syntax for environment variable for path, see actions/runner-images#1794 * Re-work path structure for project template test in ci * Setup paths again to use full path into GenerateSingleSampleHeads script * Fixed comment referencing outdated file name * Use absolute path for project references in the "All" solution * Removed leading directory separator on generated path * Update slngen to fix build issues with not finding SDK due to global.json See details in microsoft/slngen#453 * Add flag to build to enable easily getting diagnostics from tools * Clean-up labels and conditions for diagnostics * Add COREHOST_TRACE diagnostics for dotnet * Move conditional for COREHOST_TRACE into step * Just have COREHOST_TRACE defined at top * Add calling dotnet --info * Fixed missing markdown/cs files. Changed "Experiment" to "ToolkitComponent" * Revert initial work renaming Experiment to Component. * Fixed markdown exclude path * Moved project out of double nested folder * Removed restored files that should have been deleted * Move SourceGenerators.Tests project up a folder and fix in build.yml path Wasn't being built as was excluded from wildcard in solution generator * Fixed path for test output * Improved and shortened project names * Rename LabsUITestMethod to UIThreadTestMethod * Renamed to CommunityToolkit.Tooling.TestGen * New names for UITestMethodAttribute and UITestMethodGenerator * Fixed incorrect namespace * Fixed a bad find/replace * Renamed "all" component heads and App/Test shared projects * Added "App" to app head names * Fixed runtime error * Move SourceGenerators.Tests project up a folder and fix in build.yml path Wasn't being built as was excluded from wildcard in solution generator * Fixed path for test output * Improved and shortened project names * Rename LabsUITestMethod to UIThreadTestMethod * Renamed to CommunityToolkit.Tooling.TestGen * New names for UITestMethodAttribute and UITestMethodGenerator * Renamed "all" component heads and App/Test shared projects * Added "App" to app head names * Turn off diagnostics for our powershell scripts as slngen has error with diagnostics Fix diagnostic flag detection * Enable git long path support for the clean operation * Update microsoft/setup-msbuild github action * Cleaned up moved files that weren't deleted properly * Update slngen to 9.5.4 Should hopefully resolve CI issues from microsoft/slngen#453 and its initial fix --------- Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
I still meet the error:
|
@khoabui1412 Are any workaround mentionned in this comment #1127 (comment) solving the issue for you or it is still broken with the workarounds? |
@Evangelink, it's still broken, it's ok if I set app as packaged app, but my case I want to run in unpackaged mode. |
Hi @khoabui1412, Could you please let me know if you have the issue only in VS or also on command line (calling vstest.console.exe)? |
@Evangelink , it also has same error when calling by vstest.console.exe. |
@khoabui1412 I have moved to a different error (no longer on MSTest side) by setting
Could you try on your end and confirm you see the same issue? |
@Evangelink, |
HA! After I hit send, it occurred to me that maybe I didn't follow the vstest.console instructions correctly. I went back and reread the UWP instructions, pointing at the appxrecipe file instead of the DLL (and included the other parameters in the example) and... it worked! Sorry for the noise. I hope this serves to point someone else in the right direction. |
Hi @BarcoScott, Thanks for the information. It would have been better to create a different issue for your question as there is no link with the current issue. Also, vstest.console.exe related questions should be posted in https://github.com/microsoft/vstest repository. |
…lkit#360) * Moved project heads to common folder * Fixed broken reference to props file * Fix broken path references * Fixed broken file references * Fixed broken path * Move asset references to props file * Consolidated ProjectHeads and supporting infrastructure * Migrating projects to new infra * Migrating files to new infra * Added missing assemblyname and rootnamespace declaration * Fixed building WinAppSdk * Fixed build errors for UWP under "All" solution * Fixed working directory for UseTargetFrameworks.ps1 * Switch GenerateSingleSampleHeads.ps1 to use dotnet templating tool Update WindowsAppSDK version and MSTest tools Add properties to allow tests to run on 1.2.x, see microsoft/testfx#1127 Remove solution files from experiments Add bat file to copy heads and run slngen Tested locally running all heads and tests for an experiment * Update folder for linux CI build and Codespaces to WASM project * Clean-up and re-work build script for testing the project template * Use expanded form for environment variables everywhere * Use repo root path for script when in working directory of template * Use github syntax for environment variable for path, see actions/runner-images#1794 * Re-work path structure for project template test in ci * Setup paths again to use full path into GenerateSingleSampleHeads script * Fixed comment referencing outdated file name * Use absolute path for project references in the "All" solution * Removed leading directory separator on generated path * Update slngen to fix build issues with not finding SDK due to global.json See details in microsoft/slngen#453 * Add flag to build to enable easily getting diagnostics from tools * Clean-up labels and conditions for diagnostics * Add COREHOST_TRACE diagnostics for dotnet * Move conditional for COREHOST_TRACE into step * Just have COREHOST_TRACE defined at top * Add calling dotnet --info * Fixed missing markdown/cs files. Changed "Experiment" to "ToolkitComponent" * Revert initial work renaming Experiment to Component. * Fixed markdown exclude path * Moved project out of double nested folder * Removed restored files that should have been deleted * Move SourceGenerators.Tests project up a folder and fix in build.yml path Wasn't being built as was excluded from wildcard in solution generator * Fixed path for test output * Improved and shortened project names * Rename LabsUITestMethod to UIThreadTestMethod * Renamed to CommunityToolkit.Tooling.TestGen * New names for UITestMethodAttribute and UITestMethodGenerator * Fixed incorrect namespace * Fixed a bad find/replace * Renamed "all" component heads and App/Test shared projects * Added "App" to app head names * Fixed runtime error * Move SourceGenerators.Tests project up a folder and fix in build.yml path Wasn't being built as was excluded from wildcard in solution generator * Fixed path for test output * Improved and shortened project names * Rename LabsUITestMethod to UIThreadTestMethod * Renamed to CommunityToolkit.Tooling.TestGen * New names for UITestMethodAttribute and UITestMethodGenerator * Renamed "all" component heads and App/Test shared projects * Added "App" to app head names * Turn off diagnostics for our powershell scripts as slngen has error with diagnostics Fix diagnostic flag detection * Enable git long path support for the clean operation * Update microsoft/setup-msbuild github action * Cleaned up moved files that weren't deleted properly * Update slngen to 9.5.4 Should hopefully resolve CI issues from microsoft/slngen#453 and its initial fix --------- Co-authored-by: michael-hawker <24302614+michael-hawker@users.noreply.github.com>
Bumping all versions to latest, I see the following behaviors:
I am having a deeper look at why the dispatcher is not found and how to fix it. For the cases of 3, I would wait to get some strong request from users as it seems less reproducible. |
Using this test project: MSTestWinUI.zip and this test matrix
I end up with only
which is an error outside of MSTest. I have reached out to the team and will post some update here. |
I have checked with internal teams and unpackaged apps is not a supported scenario at the moment. I'll move forward by closing this ticket and opening a new one (see #2784) to add support for this feature. |
Description
After upgrading my test project to Windows App SDK 1.1 the execution of tests fails.
Steps to reproduce
I followed https://devblogs.microsoft.com/ifdef-windows/winui-desktop-unit-tests/
UITestMethod
attributed tests, fail to run after I upgrade to Windows App SDK 1.1with error message:
The exact same project work with Microsoft.WindowsAppSDK 1.0.3.
I tried to add
[assembly: WinUITestTarget(typeof(App))]
but that doesn't work either.The DispatcherQueue should get set in the OnLaunched method of my App class:
UITestMethodAttribute.DispatcherQueue = m_window.DispatcherQueue;
Expected behavior
Test should get executed.
Actual behavior
Running tests fails with message above. No window ever pops up and the App class seems to be not created.
Environment
WinAppSDK 1.1.0
VS 17.2.3
Microsoft.TestPlatform.TestHost 17.2.0
MSTest.TestFramework 2.2.10
MSTest.TestAdapter 2.2.10
.csProj (click to expand)
App.xaml.cs (click to expand)
Tests.cs (click to expand)
AB#1643611
The text was updated successfully, but these errors were encountered: