35
votes

Unit refuses to dsicover or run my tests in an assembly. This is not the case where Unit produces an error message like "Unable to find test in assembly". It simply doesn't discover that I have tests.

I right-click the test-method and the test output shows:

Discover test started ------ Discover test finished: 0 found (0:00:00,0260026)"

I have tried everything mentioned in this post: NUnit doesn't find tests in assembly

Upgrading is not a possiblity. The processor architecture settings are correct. My tests are public and have all the correct tags.

Here's some code from my project that I simply can't get to even execute. I know that because I have a break-point right at the beginning.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace UnitTestProjects
{
    [TestFixture]
    public class SomeRandomTests
    {
        [Test]
        public void ShouldFail()
        {
            Assert.AreEqual(1, 0);
        }

        [Test]
        public void ShouldPass()
        {
            Assert.AreEqual(1,1);
        }
    }
}

I'm running the internal visual studio test explorer. Unit Framework version 2.5.9.10348, runtime version v2.0.50727. I have Unit Test Adopter installed. I've attempted reinstalling it with no success.

10
So what version of NUnit are you using? Without knowing that it's hard to try to reproduce the problem. What test runner are you using? (NUnit-gui? Something else?) What happens if you run nunit-console? - Jon Skeet
Without extensions, I don't think the VS test explorer will pick up NUnit tests... it'll be expecting you to be using microsofts testing framework, which uses [TestClass] and [TestMethod] attributes on the tests... - forsvarir
I should have nunit test adapter installed. How can I verify? - user1531921
Your test Project should have a reference to Nunit.VisualStudio.TestAdapter if you've installed the adapter... or you could just try reinstalling it through nuget - forsvarir
The reference is there and I can confirm that the test adopted is installed. I tried reinstalling it from Extensions and Updates under Tools. Still no success. - user1531921

10 Answers

38
votes

You must either install the NUnit VSAdapter vsix extension, or add the adapter as nuget package to your solution.

The latest version is the 2.0, and the vsix is available here: https://visualstudiogallery.msdn.microsoft.com/6ab922d0-21c0-4f06-ab5f-4ecd1fe7175d

And the nuget package can be found here: http://www.nuget.org/packages/NUnitTestAdapter/

More information on these options can be found in this MSDN ALM post http://blogs.msdn.com/b/visualstudioalm/archive/2013/06/11/part-3-unit-testing-with-traits-and-code-coverage-in-visual-studio-2012-using-the-tfs-build-and-the-new-nuget-adapter-approach.aspx, which also points to two earlier posts.

If you look in the Output console window under Test, the adapter name and version is displayed there as it run. If it doesn't come up, the adapter is not active.

If you run Resharper, ensure you have the latest 8.2 version, there has been conflicts earlier with the test adapters and resharper.

Even if you can't upgrade this project from NUnit 2.5.9 to latest 2.6.4, you can verify the adapters work correctly in a test project using 2.6.4.
I just checked on my own machine with NUnit 2.5.9, and that worked nice with the 2.0 adapter.

Update:

For VS2017 you dont install the NUnit VSAdapter vsix extension, instead install the NUnit 3 TestAdapter for Visual Studio 2012 (Update 1) onwards. This works with NuGet package: NUnit 3.9.0.

Update 2 - June 2019 Just released the 2.2 version of the NUnit2 Adapter. It should now work properly with SDK type projects, and with VS 2017 and 2019.

2
votes

Mine is just like the same, but the different was I created my project as VS UnitTest project and not a plain DLL. So I created a DLL and referenced all the nunit assemblies and the test are now discovered.

Hope this helps.

2
votes

I had this same problem when upgrading from Visual Studio 2013 to VS 2017. In my case, all the tests were written for NUnit 2 (not 3) and worked fine in VS 2013. Once VS2017 was installed, none of the tests could be found.

The problem is that VS2017 did not automagically pick up the NUnit 2 install on my VM.

The solution was to install the Nunit 2 test runner by clicking on the Tools menu, Tools | Extensions and Updates. Next select Online on the right-hand list and then enter "NUnit" in the Search box. You can then add the appropriate NUnit test runner.

This probably applies to all test runners except perhaps MSTest.

1
votes

In my case i used TestCaseSource attribute. And passed wrong sourceName.

 [Test]
 [TestCaseSource("TestDataCaseSource")]
 public void SomeTest1(string DataName, ITestData testData)

After fixing it, all tests appears in Test Explorer

1
votes

I was also facing same issue.My tests are not discovered. After installing NUnit3TestAdapter dll from nuget package manager resolved my issue.my visual studio version is vs2017.

0
votes

Problem may be with NUnit30Settings.xml. I had this poroblem. In my case file was empty. I don't know what was the reason. I copied settings from NUnitSettings.xml to NUnit30Settings.xml. This solved my problem. Files with settings are in ...Users\[User]\AppData\Local\NUnit.

0
votes

For my case VS2017, after installation of Unit Test Adopter 3, I just add an updated version of the DLL to my solution using Nuget Package manager.

0
votes

Few things to check here . 1) Make sure we are referencing the right dlls to the test project. In our case it will be NUnit3testAdapter 2) We have to restartthe visual studio so in order for the our new install extensions to take effect .

Even after trying all of this and still it doesn't work Install it as part of ToolExtensions and update and from here install the NunitTest adapter. this should definitely work.

0
votes

I had this issue and I can reproduce it with the example code provided if I have the NUnit and the MSTest Frameworks installed, which causes the issue of 0 tests found.

Once I removed MSTest.TestAdapapter and MSTest.TestFramework packages the example code above worked.

In my own code I then had to change my attributes from the MSTest to the NUnit attributes e.g. [TestClass] to [TestFixture].

So basically check you don't have any rouge conflicting packages added.

enter image description here

0
votes

In my case the reason for the message "Discover tests finished - 0 found" was that I haven't run the updates to the Nuget packages.

Go to Tools -> Nuget Package Manager -> Manage Nuget Packages for Solution and click on the Updates tab. From there you can update the newset updates to the Nuget packages you have installed.