nunit / nunit-vs-adapter

Runs NUnit V2 tests inside the Visual Studio 2012 or later Test Explorer window.
MIT License
50 stars 43 forks source link

NUnit v3 does not discover test when TestFixture inherits from class in different assembly #158

Closed UnderHeavyDevelopment closed 7 years ago

UnderHeavyDevelopment commented 7 years ago

When I run test that is in test fixture that inherits from class containing [SetUp] AND/OR [TearDown] AND/OR [TestFixture] attribute and is located in different assembly, then test is NOT discovered.

VS Output:

No tests found to run.

Platform:

Required nugets:

Example:

---- Project Different -----

namespace Different 
{
    using NUnit.Framework;

    // Same base class, but in different than TestFixture project
    public class BaseTest
    {
        [SetUp] // POI
        public void Setup()
        {
        }

        [TearDown] // POI
        public void Teardown()
        {
        }
    }
}

---- Project Same ----

namespace Same
{
    using NUnit.Framework;

    // Same base class, but in the same as TestFixture project
    public class BaseTest
    {
        [SetUp]
        public void Setup()
        {
        }

        [TearDown]
        public void Teardown()
        {
        }
    }
}

Consider Following cases:

  1. TEST DISCOVERED: Inheriting after base class located in same assembly
namespace Same
{
    using NUnit.Framework;

    [TestFixture]
    public class Tests : Same.BaseTest // POI
    {
        [Test]
        public void Test() 
        {
        }
    }
}
  1. TEST NOT DISCOVERED: Inheriting after base class located in different assembly WITH [SetUp] and/or [TearDown] attributes
namespace Same
{
    using NUnit.Framework;

    [TestFixture]
    public class Tests : Different.BaseTest // POI
    {
        [Test]
        public void Test() 
        {
        }
    }
}
  1. TEST DISCOVERED: Inheriting after base class located in different assembly WITHOUT [SetUp] or [TearDown] attributes
---- Project Different -----

namespace Different 
{
    using NUnit.Framework;

    public class EmptyBaseTest
    {
        // POI
    }
}

---- Project Same ----

namespace Same
{
    using NUnit.Framework;

    [TestFixture]
    public class Tests : Different.EmptyBaseTest // POI
    {
        [Test]
        public void Test() 
        {
        }
    }
}
UnderHeavyDevelopment commented 7 years ago

I have the solution: Project Different had NUnit v3.7.1 package, but Project Same had NUnit v3.6.1. I wonder if this can be somehow printed as an error in Output, not "No tests found to run"?

rprouse commented 7 years ago

Excellent report, thank you. I expect that this is an issue with the NUnit Framework, not the adapter. Can you confirm that the tests are not found when you run the tests with the NUnit Console?

We had a similar issue reported nunit/nunit#2014, but it could not be reproduced. I also have tests that do the same thing that work fine.

rprouse commented 7 years ago

@UnderHeavyDevelopment our posts crossed 😄

I am going to move this to the framework repository as it is a general issue. I am not sure how we can easily detect if you are using multiple versions of the framework, but we will look into it.

rprouse commented 7 years ago

Issue moved to nunit/nunit #2316 via ZenHub