nunit/nunit-vs-adapter

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

UnderHeavyDevelopment opened this issue ยท 4 comments

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:

  • .NET Framework 4.6.1
  • VS2017 (15.2 26430.15)
  • NUnit 3 Test Adapter 3.7.0.0

Required nugets:

  • NUnit v3.7.1

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() 
        {
        }
    }
}

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"?

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.

@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.

Issue moved to nunit/nunit #2316 via ZenHub