Skip to content
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

Test execution bugs in specific TFMs addressed. #1071

Merged
merged 13 commits into from
Apr 22, 2022

Conversation

Haplois
Copy link
Contributor

@Haplois Haplois commented Apr 14, 2022

Remarks

Sample Type
PackagedAppTestSample.zip Packaged Test
UnpackagedAppTestSample.zip Unpackaged Test

From now on, WinUI packaged tests are required to specify UseWinUI property in *.csproj and set it true.

<PropertyGroup>
    <UseWinUI>true</UseWinUI>
</PropertyGroup>

Packaged apps

This blog post form @azchohfi is still current, just make sure you're using WinUI 1.0.0 or later.

Also, UseWinUI property needs to be specified.

Unpackaged apps

  1. Create a packaged WinUI application.
  2. Open .csproj file and add
    <ItemGroup>
        <ProjectCapability Include="TestContainer" />
    </ItemGroup>

    <PropertyGroup>
        <TestPlatformVersion>17.1.0-release-20220113-05</TestPlatformVersion>
        <MSTestVersion>5.0.30-dev</MSTestVersion>
        <GenerateProgramFile>false</GenerateProgramFile>
        <WindowsPackageType>None</WindowsPackageType>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="$(TestPlatformVersion)" />
        <PackageReference Include="MSTest.TestAdapter" Version="$(MSTestVersion)" />
        <PackageReference Include="MSTest.TestFramework" Version="$(MSTestVersion)" />
    </ItemGroup>
  1. In .csproj file make sure you're referencing 1.0.1+ version of Microsoft.WindowsAppSDK package.
  2. Add your test classes, if you need to run any tests in UI thread you need to specify this attribute in your test application
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;

[assembly: WinUITestTarget(typeof(App4.App))]

Building this branch to test

  1. Open a terminal window at your source root
  2. Run
.\scripts\Build.ps1 -FrameworkVersion "5.0.30" -AdapterVersion "5.0.30" 

# If a preview version of VS fails to compile you can instead run:
# .\scripts\Build.ps1 -FrameworkVersion "5.0.30" -AdapterVersion "5.0.30" -DisallowPrereleaseMSBuild
  1. You should increment the version to bypass package cache when testing - also add ./artifacts/Debug/MSTestPackages/ to your nuget.config file.

 - Fixed test execution under net5+ TFMs.
 - Fixed UWP test execution.

 - Fixes #991
 - Fixes #982
 - Fixes #750
@Haplois Haplois linked an issue Apr 14, 2022 that may be closed by this pull request
@Scottj1s
Copy link
Member

I'm concerned about false positives/negatives, as using WinUI is not equivalent to executing in a packaged app.

@Haplois
Copy link
Contributor Author

Haplois commented Apr 14, 2022

@Scottj1s
I'm concerned about false positives/negatives, as using WinUI is not equivalent to executing in a packaged app.

Currently we only support packaged WinUI applications. I am experimenting with non packaged ones. I might amend this PR to include support this weekend.

@Scottj1s
Copy link
Member

@Scottj1s
I'm concerned about false positives/negatives, as using WinUI is not equivalent to executing in a packaged app.

Currently we only support packaged WinUI applications. I am experimenting with non packaged ones. I might amend this PR to include support this weekend.

Sounds good. Also note that in addition to packaged non-WinUI apps, you can have an unpackaged WinUI app.

@Haplois
Copy link
Contributor Author

Haplois commented Apr 21, 2022

Support for unpackaged-apps are also here. See PR description for details.

@nohwnd nohwnd marked this pull request as draft April 21, 2022 06:27
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add some integration test (probably the test case we used for manual testing).

src/Adapter/Build/Net5/MSTest.TestAdapter.props Outdated Show resolved Hide resolved
src/Adapter/Build/Net5/MSTest.TestAdapter.targets Outdated Show resolved Hide resolved
src/Adapter/PlatformServices.WinUI/PackageHelpers.cs Outdated Show resolved Hide resolved
src/Adapter/PlatformServices.WinUI/PackageHelpers.cs Outdated Show resolved Hide resolved
src/TestFramework/Extension.WinUI/UITestMethodAttribute.cs Outdated Show resolved Hide resolved
src/TestFramework/Extension.WinUI/UITestMethodAttribute.cs Outdated Show resolved Hide resolved
@Haplois Haplois marked this pull request as ready for review April 22, 2022 06:44
Evangelink
Evangelink previously approved these changes Apr 22, 2022
Copy link
Member

@Evangelink Evangelink left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nit comments - feel free to ignore them.

Co-authored-by: Amaury Levé <amaury.leve@gmail.com>
@Haplois Haplois force-pushed the haplois/dev/winui-tfm-collusion branch from eb53fac to 6fe4b68 Compare April 22, 2022 07:57
@Haplois Haplois disabled auto-merge April 22, 2022 07:58
@Haplois Haplois enabled auto-merge (squash) April 22, 2022 07:59
@Haplois Haplois merged commit 6901b31 into main Apr 22, 2022
@Haplois Haplois deleted the haplois/dev/winui-tfm-collusion branch April 22, 2022 08:07
@dotMorten
Copy link
Contributor

WinUI packaged tests are required to specify UseWinUI

looking over the code it seems it is more about testing packaged apps rather than testing WinUI, or am I missing something here?

@Haplois
Copy link
Contributor Author

Haplois commented Apr 22, 2022

It also supports unpackaged apps, you can find a sample here. I'll also update the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants