简体   繁体   中英

How to get Nunit Test Adapter Framework working with .netcore 3.1

I seem to get this error when building my nunit project with .netcoreapp 3.1 and I can't figure out what mismatch version I have. I noticed a similar post on here but with a difference, where it said i should have a Nunit and UnitTestAdapter version 3.9.0 but VS won't allow me to rollback and I don't see why I would need to anyway. Error when buidling my solution is:

Any help in trying to resolve this error would be appreciated?

Package 'NUnitTestAdapter.WithFramework 2.0.0' was restored using '.NETFramework,Version=v4.6.1, 
.NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, 
.NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. 
This package may not be fully compatible with your project. 

How can NUnitTestAdapter.WithFramework 2.0.0 not be compatible with project when I have the latest packages?

My test.csproj is:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>

    <IsPackable>false</IsPackable>
  </PropertyGroup>

  <ItemGroup>
    <None Remove="App1.config" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Chromium.ChromeDriver" Version="2.37.0" />
    <PackageReference Include="Dapper" Version="2.0.90" />
    <PackageReference Include="DapperExtensions" Version="1.7.0" />
    <PackageReference Include="DotNetSeleniumExtras.WaitHelpers" Version="3.11.0" />
    <PackageReference Include="ExtentReports" Version="4.1.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
    <PackageReference Include="NUnit" Version="3.13.2" />
    <PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
    <PackageReference Include="NUnitTestAdapter.WithFramework" Version="2.0.0" />
    <PackageReference Include="RestSharp" Version="106.11.7" />
    <PackageReference Include="Selenium.Chrome.WebDriver" Version="85.0.0" />
    <PackageReference Include="Selenium.WebDriver" Version="3.141.0" />
    <PackageReference Include="SpecFlow" Version="3.8.7" />
    <PackageReference Include="SpecFlow.Assist.Dynamic" Version="1.4.2" />
    <PackageReference Include="SpecFlow.NUnit" Version="3.8.7" />
    <PackageReference Include="SpecFlow.Tools.MsBuild.Generation" Version="3.8.7" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="5.0.0" />
    <PackageReference Include="System.Data.SqlClient" Version="4.8.2" />
    <PackageReference Include="WebDriverChromeDriver" Version="2.10.0" />
  </ItemGroup>

NUnitTestAdapter.WithFramework 2.0.0 is a .net framework package (that is only supported by NUnit 2.6), and you are creating a .net core application.

Seeing as the last update for NUnitTestAdapter.WithFramework was related to VS2015, I would suggest you find a different package.

I wonder if you just chose the wrong NUnit test adapter.

Don't use that package at all. As its description says , it's only for NUnit2 projects running in Visual Studio 2012. NUnit 2 is at least 5 years old.

The NUnit documentation site explains how to use NUnit in .NET Core in .NET Core and .NET Standard . Add the latest versions of NUnit , NUnit3TestAdapter and Microsoft.NET.Test.Sdk .

In your csproj file you should add :

<ItemGroup>
  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
  <PackageReference Include="NUnit" Version="3.9.0" />
  <PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
</ItemGroup>

After that you can run tests in Visual Studio or the command line with:

dotnet test

Update

Looks like your csproj already has the correct packages. In this case you only need to remove the obsolete package

@Neil's pointed article explains it well. Make sure your project targets .Net Core 3.x framework or up. If it's .NET Standard based project then the unit tests won't run. Here what it says:

  • .NET Standard is like a Portable library in that it does not target any specific platform, but can run on any supported platform. Microsoft decided that your tests should be compiled to target a platform so they know which platform to run your tests under and you get the behavior you expect for the platform you are targeting.

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