简体   繁体   中英

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. I am able to run tests through the test explorer when targeting .NET 5.0.

Project Reunion requires net5.0-windows10.0.19041 as the target framework. When I try to run tests targeting net5.0-windows10.0.19041 the project builds but the tests do not run. 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.

[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

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

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

I had the same problem with net6.0-windows10.0.19041 instead of net5.0-windows10.0.19041. (VS 2022)

Upgrading the 3 Nuget packages in the test project to the latest versions solved it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM