MSTest v2 不会与 net5.0-windows 一起运行



我正在尝试为我们的WinUI 3开发的单元测试创建一个MSTest项目。当目标是。net 5.0时,我能够通过测试资源管理器运行测试。

项目团聚需要net5.0-windows10.0.19041作为目标框架。当我尝试以net5.0-windows10.0.19041为目标运行测试时,项目会生成,但测试不会运行。下面的测试日志的输出说WinUI3-UnitTests.dll文件没有找到,但WinUI3-UnitTests.dll确实存在于指定的位置。

[2021-10-05 9:38:57.350 AM] [MSTest][Discovery][WinUI3-DemoWinUI3-UnitTestsbinDebugnet5.0-windows10.0.19041WinUI3-UnitTests.dll] Failed to discover tests from assembly WinUI3-DemoWinUI3-UnitTestsbinDebugnet5.0-windows10.0.19041WinUI3-UnitTests.dll. Reason:File does not exist: WinUI3-DemoWinUI3-UnitTestsbinDebugnet5.0-windows10.0.19041WinUI3-UnitTests.dll

在MSTest输出日志中,它抛出一个System。InvalidOperation异常

TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.725, 12341249999384, testhost.x86.dll, AssemblyResolver.OnResolve: Resolved assembly: Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices, from path: WinUI3-DemoWinUI3-UnitTestsbinDebugnet5.0-windows10.0.19041Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.dll
TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.725, 12341250002103, testhost.x86.dll, MSTestExecutor.RunTests: Running tests from sources.
TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.728, 12341250024421, testhost.x86.dll, CollectSourceInformation value Found : False 
TpTrace Error: 0 : 4580, 4, 2021/10/01, 16:05:24.773, 12341250480636, testhost.x86.dll, Exception of type 'System.InvalidOperationException' was thrown.
TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.774, 12341250491724, testhost.x86.dll, AssemblyResolver.OnResolve: Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources: Resolving assembly.
TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.774, 12341250492593, testhost.x86.dll, AssemblyResolver.OnResolve: Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources: Searching in: 'WinUI3-DemoWinUI3-UnitTestsbinDebugnet5.0-windows10.0.19041'.
TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.774, 12341250493693, testhost.x86.dll, AssemblyResolver.OnResolve: Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources: Assembly path does not exist: 'WinUI3-DemoWinUI3-UnitTestsbinDebugnet5.0-windows10.0.19041Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources.dll', returning.
TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.775, 12341250494624, testhost.x86.dll, AssemblyResolver.OnResolve: Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources: Assembly path does not exist: 'WinUI3-DemoWinUI3-UnitTestsbinDebugnet5.0-windows10.0.19041Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources.exe', returning.
TpTrace Information: 0 : 4580, 4, 2021/10/01, 16:05:24.775, 12341250495194, testhost.x86.dll, AssemblyResolver.OnResolve: Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.resources: Failed to load assembly.

我的Nuget包参考

<PackageReference Include="Microsoft.Graphics.Win2D" Version="1.0.0.26-experimental1" />
<PackageReference Include="Microsoft.ProjectReunion" Version="0.8.4" />
<PackageReference Include="Microsoft.ProjectReunion.Foundation" Version="0.8.4" />
<PackageReference Include="Vortice.WinUI" Version="2.0.20-beta" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />

通过将MSTest.TestAdapterMSTest.TestFramework恢复到2.2.3版本解决。

我用net6.0-windows10.0.19041而不是net5.0-windows10.0.19041有同样的问题。(VS 2022)

升级3个Nuget包(Microsoft.NET.Test. exe)Sdk, MSTest。TestAdapter MSTest.TestFramework)测试项目的最新版本解决。

最新更新