Skip to content

Commit

Permalink
build: fix the build props for testing with MSTestRunner
Browse files Browse the repository at this point in the history
There is still an issue using MSTestRunner with UITests, logged in github as:
microsoft/testfx#4064

MSTestRunner is for now disabled when using UITestMethod.
  • Loading branch information
abdes committed Nov 13, 2024
1 parent 2ea7920 commit 37e1e4b
Showing 1 changed file with 49 additions and 29 deletions.
78 changes: 49 additions & 29 deletions Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -62,28 +62,6 @@
<DebugType>embedded</DebugType>
</PropertyGroup>

<!-- Test Projects -->
<Choose>
<When Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
<PropertyGroup>
<IsTestProject>True</IsTestProject>
<IsPackable>False</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
<PackageReference Include="FluentAssertions" />
</ItemGroup>
</When>
</Choose>
<ItemGroup Condition="$(MSBuildProjectName.EndsWith('.UI.Tests'))">
<PackageReference Include="Microsoft.WindowsAppSDK" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
</ItemGroup>
<ItemGroup Condition="$(MSBuildProjectName.EndsWith('.Tests')) And !$(MSBuildProjectName.EndsWith('.UI.Tests'))">
<PackageReference Include="Microsoft.NET.Test.Sdk" />
</ItemGroup>

<!-- Package Options -->
<PropertyGroup>
<IsPackable>true</IsPackable>
Expand Down Expand Up @@ -140,12 +118,54 @@
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>

<PropertyGroup Condition="$(MSBuildProjectName.EndsWith('.Tests')) And !$(MSBuildProjectName.EndsWith('.UI.Tests'))">
<!-- Enable the MSTest runner, this is an opt-in feature -->
<EnableMSTestRunner>true</EnableMSTestRunner>
<!-- We need to produce an executable and not a DLL -->
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>
<!-- Test Projects -->
<Choose>
<When Condition="$(MSBuildProjectName.EndsWith('.Tests'))">
<PropertyGroup>
<IsTestProject>True</IsTestProject>
<IsPackable>False</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectCapability Include="TestContainer" />
<PackageReference Include="Microsoft.Testing.Extensions.CodeCoverage" />
<PackageReference Include="FluentAssertions" />
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(MSBuildProjectName.EndsWith('.Tests')) And !$(MSBuildProjectName.EndsWith('.UI.Tests'))">
<PropertyGroup>
<!-- Enable the MSTest runner, this is an opt-in feature -->
<EnableMSTestRunner>true</EnableMSTestRunner>
<!-- We need to produce an executable and not a DLL -->
<OutputType>Exe</OutputType>
<TestingPlatformDotnetTestSupport>true</TestingPlatformDotnetTestSupport>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="MSTest" />
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(MSBuildProjectName.EndsWith('.UI.Tests'))">
<PropertyGroup>
<!-- Disable until https://github.com/microsoft/testfx/issues/4056 is fixed -->
<EnableMSTestRunner>false</EnableMSTestRunner>
<GenerateTestingPlatformEntryPoint Condition=" '$(EnableMSTestRunner)' == 'true' ">false</GenerateTestingPlatformEntryPoint>
<DefineConstants Condition=" '$(EnableMSTestRunner)' == 'true' ">$(DefineConstants);MSTEST_RUNNER</DefineConstants>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" />
<PackageReference Include="Microsoft.TestPlatform.TestHost" Condition="'$(EnableMSTestRunner)' != 'true'" />
<PackageReference Include="MSTest.Analyzers">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="MSTest.TestAdapter" />
<PackageReference Include="MSTest.TestFramework" />
</ItemGroup>
</When>
</Choose>

</Project>

0 comments on commit 37e1e4b

Please sign in to comment.