簡體   English   中英

MSTest v2 不能與 net5.0-windows 一起運行

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

我正在嘗試為我們的 WinUI 3 開發的單元測試創建一個 MSTest 項目。 以 .NET 5.0 為目標時,我能夠通過測試資源管理器運行測試。

Project Reunion 需要 net5.0-windows10.0.19041 作為目標框架。 當我嘗試運行針對 net5.0-windows10.0.19041 的測試時,項目構建但測試不運行。 下面測試日志的 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

在 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.

我的 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 有同樣的問題。 (對比 2022 年)

將測試項目中的3個Nuget包升級到最新版本解決了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM