nunit-core team mailing list archive
-
nunit-core team
-
Mailing list archive
-
Message #02707
[Bug 1000181] [NEW] Parameterized TestFixture with System.Type as constructor arguments fails
Public bug reported:
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.
** 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/1000181
Title:
Parameterized TestFixture with System.Type as constructor arguments
fails
Status in NUnit V2 Test Framework:
New
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/nunitv2/+bug/1000181/+subscriptions
Follow ups
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Charlie Poole, 2013-10-05
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Launchpad Bug Tracker, 2013-07-28
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Charlie Poole, 2013-07-28
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Charlie Poole, 2012-07-19
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Launchpad Bug Tracker, 2012-07-09
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Charlie Poole, 2012-07-09
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Charlie Poole, 2012-07-09
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Charlie Poole, 2012-07-05
-
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
From: Charlie Poole, 2012-05-16
-
[Bug 1000181] [NEW] Parameterized TestFixture with System.Type as constructor arguments fails
From: Jordan Terrell, 2012-05-16
References