nunit-core team mailing list archive
-
nunit-core team
-
Mailing list archive
-
Message #02832
[Bug 1000181] Re: Parameterized TestFixture with System.Type as constructor arguments fails
** Changed in: nunitv2
Status: Fix Committed => Fix Released
--
You received this bug notification because you are a member of NUnit
Core Developers, which is the registrant for NUnit Framework.
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:
Fix Released
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