-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
VSTest fails to run tests in .NET 6 test project #2985
Comments
#2218 appears to be the same behavior that was supposedly fixed. |
Is there Microsoft.NET.Test.SDK installed in your project? What is the version? |
Does this happen with a specific project or any project you generate from dotnet new? Are you able to share you project or at least the project file? What is the output of dotnet --info when run in the project folder? Are you using global.json? That error can have multiple causes, and it is never easy to know exactly which one it is, unfortunately. Here I have a project that should IMHO repro the issue that was fixed. It works on my machine: <!-- file mstest001.csproj -->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="coverlet.collector" Version="3.0.3" />
</ItemGroup>
</Project>
// file UnitTest1.cs
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace mstest001
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
}
}
} C:\t\mstest001> dotnet --version
6.0.100-preview.6.21355.2
C:\t\mstest001> dotnet test
Determining projects to restore...
All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
mstest001 -> C:\t\mstest001\bin\Debug\net6.0\win10-x64\mstest001.dll
Test run for C:\t\mstest001\bin\Debug\net6.0\win10-x64\mstest001.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.0.0-preview-20210518-01
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 13 ms - mstest001.dll (net6.0)
|
I'm not using a global.json. PS C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure.UnitTests> dotnet --version
6.0.100-preview.6.21355.2
PS C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure.UnitTests> dotnet test
Determining projects to restore...
All projects are up-to-date for restore.
You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
DOCC.Azure -> C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure\bin\Debug\net6.0\DOCC.Azure.dll
DOCC.Azure.UnitTests -> C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure.UnitTests\bin\Debug\net6.0\DOCC.Azure.UnitTests.dll
Test run for C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure.UnitTests\bin\Debug\net6.0\DOCC.Azure.UnitTests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.0.0-preview-20210518-01
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Testhost process exited with error: A fatal error was encountered. The library 'hostpolicy.dll' required to execute the application was not found in 'C:\Program Files\dotnet'.
Failed to run as a self-contained app.
- The application was run as a self-contained app because 'C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure.UnitTests\bin\Debug\net6.0\testhost.runtimeconfig.json' was not found.
- If this should be a framework-dependent app, add the 'C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure.UnitTests\bin\Debug\net6.0\testhost.runtimeconfig.json' file and specify the appropriate framework.
. Please check the diagnostic logs for more information.
Test Run Aborted.
PS C:\code\Microsoft-DevOps-Command-Center\src\DOCC.Azure.UnitTests> Here is my project.json: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Identity.Client" Version="4.34.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
<PackageReference Include="coverlet.collector" Version="3.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DOCC.Azure\DOCC.Azure.csproj" />
</ItemGroup>
</Project> I also have an empty TestClass like yours above. This is basically in a totally fresh skeleton .NET project created with command:
|
Run |
While searching to make my unit tests work for https://github.com/CommunityToolkit/Maui/tree/main/src/CommunityToolkit.Maui.UnitTests I came across this. I seem to run into the same thing and it is reproducible with this locally, on a Mac that is. It seems weird that we're building the android TFM though, but anyway, while building it as is the error is:
If I set the TFM to be
Let me know if there is anything you want me to try :) |
For .NET MAUI apps, this is now fixed and will be included in the next .NET MAUI preview: dotnet/maui#3017 |
I am having this same issue for a .NET 6 C# test automation solution, using MS .NET Test sdk 17.2.0, VS-2022, Windows-2022 on Microsoft hosted agent. https://developercommunity.visualstudio.com/t/errors-when-running-tests-with-VsTest-in/10066577 |
I have the same issue |
Steps to reproduce
I created a .NET 6 MAUI Blazor application (dotnet new maui-blazor). I added a Test Project and a very basic test (just write to console). When I try to run tests, I get the error shared below. This happens in both Visual Studio 2019 Preview and command line.
Expected behavior
Expect the test to run.
Actual behavior
No tests are run and the following is output in the Tests output
Diagnostic logs
log.txt
Environment
Running on Windows 10 19043.1110
The text was updated successfully, but these errors were encountered: