Nunit - doesn't discover tests [no error-messa

2020-05-20 08:08发布

问题:

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.

回答1:

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:

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.



回答3:

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.



回答4:

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



回答5:

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.



回答6:

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.



回答7:

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.



回答8:

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.