nunit / nunit3-vs-adapter

NUnit 3.0 Visual Studio test adapter for use under VS 2012 or later
https://nunit.org
MIT License
203 stars 105 forks source link

NUnit3TestAdapter does not find all Tests #355

Closed a-jaeger closed 7 years ago

a-jaeger commented 7 years ago

I have a TestFixture that inherits from a generic TestFixture in an other assembly. Until there is no Test in the generic base fixture, everything works fine. But when I add a Test to the base fixture, NUnit gives the following output:

NUnit Adapter 3.7.0.0: Test discovery starting Exception Mono.Cecil.AssemblyResolutionException, Exception converting Integration.GeoMan.Green.Tests.Green.MaintenableObjectRelationTests.ShouldSerializeRight_ByDefault_ReturnsFalse Failed to resolve assembly: 'Integration.GeoMan.OData.Tests, Version=1.0.0.0, Culture=neutral, PublicKeyToken=336ad8e124bdf95f' NUnit Adapter 3.7.0.0: Test discovery complete

The result is, that NO test at all is detected by NUnit in the assembly, where the inherited test fixture class is located.

The code looks like this:

namespace Integration.GeoMan.OData.Tests.Base
{
    [ExcludeFromCodeCoverage]
    public abstract class MaintainableObjectRelationBaseTests<TNode, TRelation, TRelationType>
        where TNode : DataPoolEntity
        where TRelationType : RelationType
        where TRelation : Relation<TNode, TRelationType>, new()
    {

            private static TRelation CreateRelation()
            {
                return new TRelation();
            }

            [Test]
            public void ShouldSerializeRight_ByDefault_ReturnsFalse()
            {
                var relation = CreateRelation();

                var result = relation.ShouldSerializeRight();

                Assert.That(result, Is.False);
            }
    }

In the other assembly:

namespace Integration.GeoMan.Green.Tests.Green
{
    [TestFixture]
    public class MaintenableObjectRelationTests:MaintainableObjectRelationBaseTests<MaintenableObject, MaintenableObjectRelation, MaintenableObjectRelationType>
    {
        [Test]
        public void Test_For_Me()
        {
            Assert.Fail();
        }
    }
}

If I comment the attribute [Test] of the method ShouldSerializeRight_ByDefault_ReturnsFalse, everything works fine. All tests of the Integration.GeoMan.Green.Tests assembly are recognised and executed. I have tried to find a minimum example. But for now I was not able to reduce my problem. How can I provide you with with mor information?

Im am Using NUnit3TestAdapter 3.7.0.0 and Visual Studio Enterprise 2015, Update 3 (14.0.25431.01). My solution is .net Framework 4.5.

a-jaeger commented 7 years ago

After deleting everything in the solution I found out, that one or more projects directly referenced a nunit.framwerk.dll with version 3.2.1. Using the latest nuget package of nunit in all projects resolved the problem.

jnm2 commented 7 years ago

@OsirisTerje Is this a bug? It shouldn't matter if the two assemblies containing the base and derived fixture classes reference different versions of NUnit.Framework, should it?

OsirisTerje commented 7 years ago

@jnm2 Normally it should not matter. I am pretty sure I have had this case, not with 3.2.1 necessarily, and with different tests, and have had no issues with that.
But as you say in this case the classes inherit each other, so that makes it a bit more special. I am not quite sure what we should expect in this case. Note they only compile against different versions, and thus different assemblies, but runs against one of them. I wonder if this is related to the other issue we have with inheriting from generic classes in different assembles, but I thought that one was resolved. I'll have a closer look at this one.

CharliePoole commented 7 years ago

@OsirisTerje I don't think this is particular to the adapter. We have routinely received questions about mixing framework versions over the years and the answer is always that it is not possible.

Using two different assemblies will allow you to compile but at runtime only one framework can be loaded. The assembly that references the other version causes an exception.

The user should change the code so both assemblies use the same framework version. If the base assembly is out of the user's control - e.g. a third party assembly - then the derived classes must use it's framework version.

It's also possible to deal with this through assembly bindings.

OsirisTerje commented 7 years ago

@CharliePoole Thanks, Charlie, that confirms it.

a-jaeger commented 7 years ago

It's a pleasure to see, that you even take self closed issues to enhance nunit. This is very professional. Thanks very much.