← Back to team overview

nunit-core team mailing list archive

[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails

 

** Changed in: nunitv2
       Status: New => Triaged

** Changed in: nunitv2
   Importance: Undecided => Medium

** Also affects: nunit-3.0
   Importance: Undecided
       Status: New

** Changed in: nunit-3.0
       Status: New => Triaged

** Changed in: nunit-3.0
   Importance: Undecided => Medium

-- 
You received this bug notification because you are a member of NUnit
Developers, which is subscribed to NUnit V2.
https://bugs.launchpad.net/bugs/1000181

Title:
  Parameterized TestFixture with System.Type as constructor arguments
  fails

Status in NUnit Test Framework:
  Triaged
Status in NUnit V2 Test Framework:
  Triaged

Bug description:
  When you create a parameterized test fixture that takes System.Type
  instances as constructor parameters, NUnit is unable to locate a
  suitable constructor even when one exists.  For example:

  [TestFixture(typeof(int))]
  [TestFixture(typeof(string))]
  public class TestsOnType
  {
      private readonly Type _someType;

      public TestsOnType(Type someType)
      {
          _someType = someType;
      }

      [Test]
      public void MakeSureTypeIsInSystemNamespace()
      {
          Assert.AreEqual("System", _someType.Namespace);
      }
  }

  A workaround exists, however it's not obvious.  You have to set the
  TypeArgs property of the TestFixture attributes to a non-null, empty
  array:

  [TestFixture(typeof(int), TypeArgs = new Type[0])]
  [TestFixture(typeof(string), TypeArgs = new Type[0])]

  This indicates that NUnit is assuming that any arguments provided to
  the TestFixture attribute of System.Type should be used as type
  arguments for a generic test fixture.  This is further indicated by
  the fact that the following works:

  [TestFixture(42, typeof(int))]
  [TestFixture(42, typeof(string))]
  public class TestsOnType
  {
      private readonly Type _someType;

      public TestsOnType(int ignored, Type someType)
      {
          _someType = someType;
      }

      [Test]
      public void MakeSureTypeIsInSystemNamespace()
      {
          Assert.AreEqual("System", _someType.Namespace);
      }
  }

  Above, an arbitrary ignored argument is provided to the TestFixture
  attribute (the number 42) and this enables NUnit to find a suitable
  constructor.  NUnit must be grabbing the first arguments of
  System.Type and assuming they should be used for generic type
  arguments.  Perhaps a better approach would be to see how many generic
  type arguments the test class requires and grab only that number of
  arguments.

  Please update NUnit to support parameterized test fixture classes that
  take only System.Type arguments.

To manage notifications about this bug go to:
https://bugs.launchpad.net/nunit-3.0/+bug/1000181/+subscriptions


References