Joshua Duxbury
Joshua Duxbury

Reputation: 5260

NUnit v3 unit tests not being discovered - "Discover test finished: 0 found"

Test class

[TestFixture]
public class Class1
{
    [Test]
    public void testtesttest()
    {
        Assert.IsTrue(true);
    }
}

Dependencies

Enter image description here

I followed instructions from here.

Why can't I discover my unit tests?

Upvotes: 1

Views: 1306

Answers (1)

Joshua Duxbury
Joshua Duxbury

Reputation: 5260

.NET Core Solution

It turns out I had to have a unit test project instead of a class library:

Unit Test project

I also followed instructions from the MSDN website here.

I was running the following in a command prompt to make sure I had the unit test template:

dotnet new -i NUnit3.DotNetNew.Template

My NuGet Packages Dependencies

  <ItemGroup>
    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
    <PackageReference Include="MSTest.TestAdapter" Version="1.2.0" />
    <PackageReference Include="MSTest.TestFramework" Version="1.2.0" />
    <PackageReference Include="NUnit" Version="3.8.1" />
    <PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
  </ItemGroup>

Update

As @Lexli pointed out, you don't need the MSTest packages if you are only going to use NUnit tests.

However, make sure you use .NET Core and not .Netcore Standard. The .NET Core comes with the Microsoft.netCore.App SDK which is needed for running unit tests. Unit tests can't be run with .NET standard class libraries.

Projects Referencing .NET Framework 4.0

In projects where the .NET framework was v4.0 I had to use NUnit version 3.0 - anything higher and the project wasn't discovered.

Still not working?

Try clearing temporary files located in the %TEMP% directory.

Note: This path is generally at C:\Users\(yourusername)\AppData\Local\Temp

Upvotes: 5

Related Questions