简体   繁体   English

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

[英]MSTest v2 won't run with net5.0-windows

I am trying to create a MSTest project for unit testing of our WinUI 3 development.我正在尝试为我们的 WinUI 3 开发的单元测试创建一个 MSTest 项目。 I am able to run tests through the test explorer when targeting .NET 5.0.以 .NET 5.0 为目标时,我能够通过测试资源管理器运行测试。

Project Reunion requires net5.0-windows10.0.19041 as the target framework. Project Reunion 需要 net5.0-windows10.0.19041 作为目标框架。 When I try to run tests targeting net5.0-windows10.0.19041 the project builds but the tests do not run.当我尝试运行针对 net5.0-windows10.0.19041 的测试时,项目构建但测试不运行。 The output of the Test log below says the WinUI3-UnitTests.dll file is not found but WinUI3-UnitTests.dll does exist in the specified location.下面测试日志的 output 说 WinUI3-UnitTests.dll 文件未找到,但 WinUI3-UnitTests.dll 确实存在于指定位置。

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

In the MSTest output log it throws a System.InvalidOperation exception在 MSTest output 日志中,它引发 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-Demo\WinUI3-UnitTests\bin\Debug\net5.0-windows10.0.19041\Microsoft.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-Demo\WinUI3-UnitTests\bin\Debug\net5.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-Demo\WinUI3-UnitTests\bin\Debug\net5.0-windows10.0.19041\Microsoft.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-Demo\WinUI3-UnitTests\bin\Debug\net5.0-windows10.0.19041\Microsoft.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.

My Nuget packages for reference我的 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" />

Resolved by reverting MSTest.TestAdapter and MSTest.TestFramework back to version 2.2.3.通过将MSTest.TestAdapterMSTest.TestFramework恢复到版本 2.2.3 解决。

I had the same problem with net6.0-windows10.0.19041 instead of net5.0-windows10.0.19041.我对 net6.0-windows10.0.19041 而不是 net5.0-windows10.0.19041 有同样的问题。 (VS 2022) (对比 2022 年)

Upgrading the 3 Nuget packages in the test project to the latest versions solved it.将测试项目中的3个Nuget包升级到最新版本解决了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 net5.0-windows:警告 CA1416:“windows”支持“RegistryValueKind.DWord” - net5.0-windows: warning CA1416: 'RegistryValueKind.DWord' is supported on 'windows' 仅在 Windows 上:net5.0-windows(或 net6.0-windows)是否允许我在 .Net 5(或 .Net 6)中重新编译 .Net 框架? - On Windows only: does net5.0-windows (or net6.0-windows) allow me to recompile .Net framework in .Net 5 ( or .Net 6)? 有没有办法让 VSC 的 c# 插件在 ubuntu linux 上用于目标 net5.0-windows 的项目? - Is there a way to get the c# plugin for VSC to work on ubuntu linux for a project with target net5.0-windows? MSTest v2 有序测试 - MSTest v2 Ordered Tests MSTest V2 按顺序执行单元测试 -> [DoNotParallelize] - MSTest V2 Execute UnitTests sequentially -> [DoNotParallelize] MSTest v2 和源 IQueryable 未使用 Entity Framework Core 实现 IAsyncEnumerable - MSTest v2 and The source IQueryable doesn't implement IAsyncEnumerable with Entity Framework Core 在Windows 7计算机上编写/编译的.NET 4程序将无法在XP上运行 - .NET 4 Program written/compiled on Windows 7 machine won't run on XP EXO PowerShell V2 模块远程 session Cryptography.SHA256Cng 错误与 .NET 5.0 - EXO PowerShell V2 Module remote session Cryptography.SHA256Cng error with .NET 5.0 具有x86和x64的MSTest V2 - MSTest V2 with x86 and x64 从命令行运行时,mstest v2会忽略ExpectedException - ExpectedException ignored by mstest v2 when running from the command line
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM