Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get NUnit3TestAdapter to work with .Net Standard 2.0?

How can I get NUnit3TestAdapter to work with .Net Standard 2.0?

I receive the following error:

1>C:\Nikeza\Mobile\Nikeza.Mobile\Tests\ExampleBased.fsproj :

warning NU1701: Package 'NUnit3TestAdapter 3.9.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'.

This package may not be fully compatible with your project. 1>ExampleBased -> C:\Nikeza\Mobile\Nikeza.Mobile\Tests\bin\Debug\netstandard2.0\ExampleBased.dll

like image 222
Scott Nimrod Avatar asked Dec 31 '17 13:12

Scott Nimrod


People also ask

Does NUnit support .NET standard?

0 of the NUnit Adapter does work with . NET Standard 2.0 and F#.

Is .NET framework 4.8 compatible with standard?

You cannot consume a . Net Standard 2.1 assembly in any . Net Framework Version because the . NET Framework (even the last ever version, 4.8) does not implement .


Video Answer


1 Answers

You don't provide enough information to diagnose what is wrong with your project file, but it 3.9.0 of the NUnit Adapter does work with .NET Standard 2.0 and F#. I think that your test project is targeting .NET Standard. It needs to target .NET Core or .NET 4.6.1+. Test projects are treated like executables, they need to target a specific framework, not .NET Standard. The code that you are testing can be .NET Standard though.

You should follow the documentation Unit testing F# libraries in .NET Core using dotnet test and NUnit and read the NUnit docs, .NET Core and .NET Standard.

Your project file should look something like this,

<Project Sdk="Microsoft.NET.Sdk">    <PropertyGroup>     <TargetFramework>netcoreapp2.0</TargetFramework>      <IsPackable>false</IsPackable>   </PropertyGroup>    <ItemGroup>     <Compile Include="Tests.fs" />     <Compile Include="Program.fs" />   </ItemGroup>    <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>    <ItemGroup>     <ProjectReference Include="..\MathService\MathService.fsproj" />   </ItemGroup>  </Project> 
like image 92
Rob Prouse Avatar answered Sep 30 '22 22:09

Rob Prouse