In spite of adding NUnit from NuGet to an existing .Net Core project, no unit tests are being shown in the Test Pad.
Note: I posted these images as links because I have too low of a reputation to post images. What's up with that?
I've tried restarting Visual Studio and reinstalling the package.
I've also tried deleting the Project/obj directory -- still no luck.
using NUnit.Framework;
namespace ExampleLib
{
[TestFixture]
public class ExampleTestFixture
{
[Test]
public void ExampleTest()
{
Assert.AreEqual(2, 2);
}
}
}
Expected: Tests fill the Unit Test pad Actual: Empty test pad.
There are multiple requirements of that project, so that VS for Mac can identify and execute the test cases.
Microsoft.NET.Test.Sdk
(required by VSTest infrastructure).NUnit
.NUnit3TestAdapter
(required by VSTest infrastructure).Example,
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit" Version="3.11.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.12.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>
</Project>
Note that VS for Windows and VS for Mac (and JetBrains Rider) all use VSTest for unit testing, so this setup works for all such IDEs.
Also note that if you didn't create this console project from dotnet new nunit
, but a normal console application template, you need to manually delete the Main
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With