Skip to content

Commit

Permalink
Test execution bugs in specific TFMs addressed.
Browse files Browse the repository at this point in the history
 - Fixed test execution under net5+ TFMs.
 - Fixed UWP test execution.

 - Fixes #991
 - Fixes #982
 - Fixes #750
  • Loading branch information
Haplois committed Apr 14, 2022
1 parent 73741bd commit 21ad8d0
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 74 deletions.
26 changes: 17 additions & 9 deletions TestFx.sln
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NetCore", "NetCore", "{D11C
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PlatformServices.WinUI", "src\Adapter\PlatformServices.WinUI\PlatformServices.WinUI.csproj", "{F4E2876F-6E42-4DCF-B629-041A9DF7C579}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WinUI", "WinUI", "{35D010CC-CDF2-4115-BCFB-E2E3D21C1055}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Net5", "Net5", "{35D010CC-CDF2-4115-BCFB-E2E3D21C1055}"
ProjectSection(SolutionItems) = preProject
src\Adapter\Build\WinUI\MSTest.TestAdapter.props = src\Adapter\Build\WinUI\MSTest.TestAdapter.props
src\Adapter\Build\WinUI\MSTest.TestAdapter.targets = src\Adapter\Build\WinUI\MSTest.TestAdapter.targets
src\Adapter\Build\Net5\MSTest.TestAdapter.props = src\Adapter\Build\Net5\MSTest.TestAdapter.props
src\Adapter\Build\Net5\MSTest.TestAdapter.targets = src\Adapter\Build\Net5\MSTest.TestAdapter.targets
src\Adapter\Build\Net5\MSTest.TestFramework.props = src\Adapter\Build\Net5\MSTest.TestFramework.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReferencedProjectFromDataSourceTest", "test\E2ETests\TestAssets\ReferencedProjectFromDataSourceTest\ReferencedProjectFromDataSourceTest.csproj", "{6B4DE65C-4162-4C52-836A-8F9FA901814A}"
Expand All @@ -224,13 +225,13 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlatformServices.Desktop.Le
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OutputTestProject", "test\E2ETests\TestAssets\OutputTestProject\OutputTestProject.csproj", "{66608D86-416A-49AF-A937-C47F7E4586AE}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Desktop.Legacy", "Desktop.Legacy", "{DE6887A6-D4B8-4D77-98D3-CC87A8F21C2E}"
ProjectSection(SolutionItems) = preProject
src\Adapter\Build\Desktop.Legacy\MSTest.TestAdapter.props = src\Adapter\Build\Desktop.Legacy\MSTest.TestAdapter.props
src\Adapter\Build\Desktop.Legacy\MSTest.TestAdapter.targets = src\Adapter\Build\Desktop.Legacy\MSTest.TestAdapter.targets
EndProjectSection
EndProject
Global
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Adapter\PlatformServices.Shared\PlatformServices.Shared.projitems*{2177c273-ae07-43b3-b87a-443e47a23c5a}*SharedItemsImports = 13
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{23b9d9a2-4aee-47e6-97b5-060df21539fb}*SharedItemsImports = 5
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{272ca5e1-8e81-4825-9e47-86cce02f700d}*SharedItemsImports = 13
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{df131865-84ee-4540-8112-e88acebdea09}*SharedItemsImports = 4
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Code Analysis Debug|Any CPU = Code Analysis Debug|Any CPU
Code Analysis Debug|ARM = Code Analysis Debug|ARM
Expand Down Expand Up @@ -1447,8 +1448,15 @@ Global
{44A504D9-A0D6-427D-BFB2-DB144A74F0D5} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{F64A748C-DDBA-4B57-99F4-D9E55684A7A4} = {24088844-2107-4DB2-8F3F-CBCA94FC4B28}
{66608D86-416A-49AF-A937-C47F7E4586AE} = {D53BD452-F69F-4FB3-8B98-386EDA28A4C8}
{DE6887A6-D4B8-4D77-98D3-CC87A8F21C2E} = {CA01DAF5-8D9D-496E-9AD3-94BB7FBB2D34}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {31E0F4D5-975A-41CC-933E-545B2201FAF9}
EndGlobalSection
GlobalSection(SharedMSBuildProjectFiles) = preSolution
src\Adapter\PlatformServices.Shared\PlatformServices.Shared.projitems*{2177c273-ae07-43b3-b87a-443e47a23c5a}*SharedItemsImports = 13
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{23b9d9a2-4aee-47e6-97b5-060df21539fb}*SharedItemsImports = 5
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{272ca5e1-8e81-4825-9e47-86cce02f700d}*SharedItemsImports = 13
src\TestFramework\Extension.Shared\Extension.Shared.projitems*{df131865-84ee-4540-8112-e88acebdea09}*SharedItemsImports = 4
EndGlobalSection
EndGlobal
4 changes: 4 additions & 0 deletions src/Adapter/Build/Net5/MSTest.TestAdapter.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@
<PropertyGroup>
<EnableMSTestV2CopyResources Condition=" '$(EnableMSTestV2CopyResources)' == '' ">true</EnableMSTestV2CopyResources>
</PropertyGroup>
<PropertyGroup Condition=" '$(UseWinUI)' == 'true' ">
<__TestAdapterPlatformServicesRoot>$(MSBuildThisFileDirectory)winui/</__TestAdapterPlatformServicesRoot>
</PropertyGroup>
<PropertyGroup Condition=" '$(UseWinUI)' != 'true' ">
<__TestAdapterPlatformServicesRoot>$(MSBuildThisFileDirectory)</__TestAdapterPlatformServicesRoot>
</PropertyGroup>

<ItemGroup>
<TestAdapterContent Include="$(MSBuildThisFileDirectory)..\_common\Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll">
<Link>Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</TestAdapterContent>
<TestAdapterContent Include="$(MSBuildThisFileDirectory)..\_common\Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll">
<Link>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</TestAdapterContent>
<TestAdapterContent Include="$(__TestAdapterPlatformServicesRoot)Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll">
<Link>Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</TestAdapterContent>
<TestAdapterContent Include="$(MSBuildThisFileDirectory)\Microsoft.TestPlatform.AdapterUtilities.dll">
<Link>Microsoft.TestPlatform.AdapterUtilities.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>False</Visible>
</TestAdapterContent>
</ItemGroup>

<ItemGroup>
<!-- Including `@(TestAdapterContent)` in the `None` ItemGroup to get the `CopyToOutputDirectory`
behavior be default, package consumers can opt-out of this behavior
by removing `@(TestAdapterContent)` from the `None` ItemGroup
i.e. `<None Remove="@(TestAdapterContent)" />` -->
<None Include="@(TestAdapterContent)" />
</ItemGroup>

<Target Name="GetMSTestV2CultureHierarchy">
<!-- Only traversing 5 levels in the culture hierarchy. This is the maximum lenght for all cultures and should be sufficient to get to a culture name that maps to a resource folder we package.
Expand All @@ -19,7 +56,6 @@

<!-- Copy resources over to $(TargetDir) if this is a localized build. -->
<Target Name="CopyMSTestV2Resources" BeforeTargets="PrepareForBuild" Condition=" '$(EnableMSTestV2CopyResources)' == 'true' " DependsOnTargets="GetMSTestV2CultureHierarchy">

<PropertyGroup>
<CurrentUICultureHierarchy>%(CurrentUICultureHierarchy.Identity)</CurrentUICultureHierarchy>
</PropertyGroup>
Expand All @@ -28,7 +64,7 @@
<MSTestV2Files Include="$(MSBuildThisFileDirectory)..\_common\*.dll" />
</ItemGroup>

<ItemGroup>
<ItemGroup>
<Content Include="@(MSTestV2Files->'%(RootDir)%(Directory)$(CurrentUICultureHierarchy)\%(FileName).resources.dll')"
Condition="Exists('%(RootDir)%(Directory)$(CurrentUICultureHierarchy)\%(FileName).resources.dll')">
<Link>$(CurrentUICultureHierarchy)\%(FileName).resources.dll</Link>
Expand All @@ -38,5 +74,4 @@
</Content>
</ItemGroup>
</Target>

</Project>
17 changes: 17 additions & 0 deletions src/Adapter/Build/Net5/MSTest.TestFramework.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(UseWinUI)' == 'true' ">
<_TestFrameworkExtensionsRoot>$(MSBuildThisFileDirectory)winui/</_TestFrameworkExtensionsRoot>
</PropertyGroup>
<PropertyGroup Condition=" '$(UseWinUI)' != 'true' ">
<_TestFrameworkExtensionsRoot>$(MSBuildThisFileDirectory)</_TestFrameworkExtensionsRoot>
</PropertyGroup>

<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions">
<HintPath>$(_TestFrameworkExtensionsRoot)Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<!-- <Visible>False</Visible> -->
</Reference>
</ItemGroup>
</Project>
33 changes: 0 additions & 33 deletions src/Adapter/Build/WinUI/MSTest.TestAdapter.props

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.3\Utilities\ns13DeploymentItemUtility.cs" Link="Utilities\ns13DeploymentItemUtility.cs" />
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.3\Utilities\ns13DeploymentUtilityBase.cs" Link="Utilities\ns13DeploymentUtilityBase.cs" />
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.3\Utilities\ns13FileUtility.cs" Link="Utilities\ns13FileUtility.cs" />
<Compile Include="..\PlatformServices.Shared\netstandard1.3\Services\ns13ThreadSafeStringWriter.cs" Link="ns13ThreadSafeStringWriter.cs" />
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.3\Services\ns13ThreadSafeStringWriter.cs" Link="Services\ns13ThreadSafeStringWriter.cs" />
<Compile Include="Deployment\NetCoreTestRunDirectories.cs" />
<Compile Include="Friends.cs" />
<Compile Include="Services\NetCoreTestContextImplementation.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public class TestContextImplementation : UTF.TestContext, ITestContext
/// </summary>
private ITestMethod testMethod;

private StringWriter stringWriter;
private ThreadSafeStringWriter threadSafeStringWriter;
private bool stringWriterDisposed;

/// <summary>
Expand All @@ -62,7 +62,7 @@ public TestContextImplementation(ITestMethod testMethod, StringWriter writer, ID

this.testMethod = testMethod;
this.properties = new Dictionary<string, object>(properties);
this.stringWriter = writer;
this.threadSafeStringWriter = (ThreadSafeStringWriter)writer;
this.CancellationTokenSource = new CancellationTokenSource();
this.InitializeProperties();
}
Expand Down Expand Up @@ -204,7 +204,7 @@ public override void Write(string message)
try
{
var msg = message?.Replace("\0", "\\0");
this.stringWriter.Write(msg);
this.threadSafeStringWriter.Write(msg);
}
catch (ObjectDisposedException)
{
Expand All @@ -228,7 +228,7 @@ public override void Write(string format, params object[] args)
try
{
string message = string.Format(CultureInfo.CurrentCulture, format?.Replace("\0", "\\0"), args);
this.stringWriter.Write(message);
this.threadSafeStringWriter.Write(message);
}
catch (ObjectDisposedException)
{
Expand All @@ -251,7 +251,7 @@ public override void WriteLine(string message)
try
{
var msg = message?.Replace("\0", "\\0");
this.stringWriter.WriteLine(msg);
this.threadSafeStringWriter.WriteLine(msg);
}
catch (ObjectDisposedException)
{
Expand All @@ -275,7 +275,7 @@ public override void WriteLine(string format, params object[] args)
try
{
string message = string.Format(CultureInfo.CurrentCulture, format?.Replace("\0", "\\0"), args);
this.stringWriter.WriteLine(message);
this.threadSafeStringWriter.WriteLine(message);
}
catch (ObjectDisposedException)
{
Expand All @@ -298,16 +298,15 @@ public IList<string> GetResultFiles()
/// <returns>The test context messages added so far.</returns>
public string GetDiagnosticMessages()
{
return this.stringWriter.ToString();
return this.threadSafeStringWriter.ToString();
}

/// <summary>
/// Clears the previous testContext writeline messages.
/// </summary>
public void ClearDiagnosticMessages()
{
var sb = this.stringWriter.GetStringBuilder();
sb?.Remove(0, sb.Length);
this.threadSafeStringWriter.ToStringAndClear();
}

public void SetDataRow(object dataRow)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />

<PropertyGroup>
<ProjectGuid>{5D153CAA-80C2-4551-9549-6C406FCEEFB1}</ProjectGuid>
<OutputType>Library</OutputType>
Expand All @@ -18,14 +17,12 @@
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<NoWarn>2008</NoWarn>
</PropertyGroup>

<PropertyGroup>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<ResolveAssemblyReferencesSilent>true</ResolveAssemblyReferencesSilent>
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<PlatformTarget>$(Platform)</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
Expand All @@ -46,7 +43,6 @@
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<UseVSHostingProcess Condition=" '$(Platform)' != 'AnyCPU' ">false</UseVSHostingProcess>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="$(RepoRoot)src\TestFramework\MSTest.Core\MSTest.Core.csproj">
<Project>{7252d9e3-267d-442c-96bc-c73aef3241d6}</Project>
Expand All @@ -64,7 +60,6 @@
<Private>False</Private>
</ProjectReference>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.TestPlatform.ObjectModel" Version="$(MicrosoftNETTestSdkVersion)" />
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="$(MicrosoftNETCoreUniversalWindowsPlatformVersion)" targetFramework="net452" />
Expand All @@ -74,15 +69,13 @@
<PackageReference Include="System.Text.RegularExpressions" Version="$(SystemTextRegularExpressionsVersion)" />
<!-- CVE-2019-0981, CVE-2019-0980, CVE-2019-0657 -->
<PackageReference Include="System.Private.Uri" Version="$(SystemPrivateUriVersion)" />

<PackageReference Include="MicroBuild.Core" Version="$(MicroBuildCoreVersion)" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="StyleCop.Analyzers" Version="$(StyleCopAnalyzersVersion)" PrivateAssets="all">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.0\Constants.cs">
<Link>Constants.cs</Link>
Expand Down Expand Up @@ -123,6 +116,9 @@
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.0\Services\ns10TraceListenerManager.cs">
<Link>Services\ns10TraceListenerManager.cs</Link>
</Compile>
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.3\Services\ns13ThreadSafeStringWriter.cs">
<Link>Services\ns13ThreadSafeStringWriter.cs</Link>
</Compile>
<Compile Include="Friends.cs" />
<Compile Include="Services\UniversalAdapterTraceLogger.cs" />
<Compile Include="Services\UniversalFileOperations.cs" />
Expand All @@ -133,6 +129,5 @@
<PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0' ">
<VisualStudioVersion>15.0</VisualStudioVersion>
</PropertyGroup>

<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.0\Services\ns10TraceListenerManager.cs">
<Link>Services\ns10TraceListenerManager.cs</Link>
</Compile>
<Compile Include="$(RepoRoot)src\Adapter\PlatformServices.Shared\netstandard1.3\Services\ns13ThreadSafeStringWriter.cs" Link="Services\ns13ThreadSafeStringWriter.cs" />
<Compile Include="Friends.cs" />
<Compile Include="Services\WinUIAdapterTraceLogger.cs" />
<Compile Include="Services\WinUIFileOperations.cs" />
Expand Down
Loading

0 comments on commit 21ad8d0

Please sign in to comment.