TestFixture attributes on base classes are not ignored

Bug #701331 reported by Isaac Devine
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
NUnit V2
Status tracked in Trunk
2.5
Fix Released
Medium
Charlie Poole
Trunk
Fix Released
Medium
Charlie Poole

Bug Description

Using Nunit 2.5.9 GUI Runner & 2.5.9 framework.

TestFixutre attributes on derived classes should replace any declared on superclasses, which is what is described in the documentation:

http://nunit.org/index.php?p=testFixture&r=2.5.9
----------------------------------------------------------------
 Inheritance

The TestFixtureAttribute may be applied to a base class and is inherited by any derived classes. This includes any abstract base class, so the well-known Abstract Fixture pattern may be implemented if desired.

In order to facilitate use of generic and/or parameterized classes, where the derived class may require a different number of arguments (or type arguments) from the base class, any TestFixture attribute on a derived class causes those on the base classes to be ignored.
-----------------------------------------------------------------

However this isn't happening as the following test case shows.

Reproducible Test Case:
-------------------------------------------------------------
    [TestFixture(typeof(TagClassDefault))]
    public abstract class AbstractBase<T>
    {
        [Test]
        public void TestMethod()
        {
        }
    }

    [TestFixture(typeof(TagClassCustom))]
    public class ConcreteClass<T> : AbstractBase<T>
    {
    }

    public class TagClassDefault
    {
    }

    public class TagClassCustom
    {
    }

-----------------------------------

Expected Behaviour:
 ConcreteClass is constructed with the TagClassCustom type parameter only

Actual Behaviour:
 ConcreateClass is constructed twice, once with TagClassCustom, the other with TagClassDefault

Revision history for this message
Isaac Devine (isaac-devine) wrote :

NOTE: Nunit 2.5.5 acts as expected

Revision history for this message
Charlie Poole (charlie.poole) wrote : Re: [Bug 701331] [NEW] TestFixture attributes on base classes are not ignored

Just to be clear, the example given is not from the docs, as it seems
from reading the bug description. The behavior still seems odd though.

Charlie

On Mon, Jan 10, 2011 at 6:27 PM, Isaac Devine <email address hidden> wrote:
> Public bug reported:
>
> Using Nunit 2.5.9 GUI Runner & 2.5.9 framework.
>
> TestFixutre attributes on derived classes should replace any declared on
> superclasses, which is what is described in the documentation:
>
> http://nunit.org/index.php?p=testFixture&r=2.5.9
> ----------------------------------------------------------------
>  Inheritance
>
> The TestFixtureAttribute may be applied to a base class and is inherited
> by any derived classes. This includes any abstract base class, so the
> well-known Abstract Fixture pattern may be implemented if desired.
>
> In order to facilitate use of generic and/or parameterized classes, where the derived class may require a different number of arguments (or type arguments) from the base class, any TestFixture attribute on a derived class causes those on the base classes to be ignored. This allows use of code like the following:
> -----------------------------------------------------------------
>
> Example:
> -------------------------------------------------------------
>    [TestFixture(typeof(TagClassDefault))]
>    public abstract class AbstractBase<T>
>    {
>        [Test]
>        public void TestMethod()
>        {
>        }
>    }
>
>
>    [TestFixture(typeof(TagClassCustom))]
>    public class ConcreteClass<T> : AbstractBase<T>
>    {
>    }
>
>
>    public class TagClassDefault
>    {
>    }
>
>    public class TagClassCustom
>    {
>    }
>
> -----------------------------------
>
> Expected Behaviour:
>  ConcreteClass is constructed with the TagClassCustom type parameter only
>
> Actual Behaviour:
>  ConcreateClass is constructed twice, once with TagClassCustom, the other with TagClassDefault
>
> ** Affects: nunitv2
>     Importance: Undecided
>         Status: New
>
> --
> You received this bug notification because you are a member of NUnit
> Developers, which is subscribed to NUnit V2.
> https://bugs.launchpad.net/bugs/701331
>
> Title:
>  TestFixture attributes on base classes are not ignored
>

description: updated
Changed in nunitv2:
status: New → Triaged
importance: Undecided → Medium
Changed in nunitv2:
milestone: none → 2.5.10
Revision history for this message
Charlie Poole (charlie.poole) wrote :

The documentation reflected an earlier version of the code and was no longer correct. It has now been corrected online.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.