Parameterized testfixture with default ctor

Asked by Roger Kratz

Hi

Are there any plans having similar functionality as parameterized testfixture but instead of ctor injection setting a prop? Or can I achieve what I want some other way?

Background...

I have around 1000 unit test where most of them derive from a common base class. I would like my tests to run twice with different configuration - parameterized testfixtures (indata declared as attributes on base type). It works just fine but I would prefer not having to impl an explicit ctor on all my test fixtures.

Today....

[TestFixture("foo")]
[TestFixture("bar")]
public abstract class TestBase
{
    ctor(string)
}
public class TestFixture : TestBase
{
    ctor(string)
}

...I would prefer something like this or similar....
[TestFixture("SomeValue", "foo")]
[TestFixture("SomeValue", "bar"")]
public abstract class TestBase
{
    public string SomeValue {get;set;}
}
public class TestFixture : TestBase
{
}

Regards
Roger

Question information

Language:
English Edit question
Status:
Answered
For:
NUnit V2 Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.

Revision history for this message
Charlie Poole (charlie.poole) said :
#2

Very strange... I answered this by email on Feb 28, but it doesn't seem to have shown up here. There seem to be problems with posting to bugs and questions by email. I'll paste the answer here now...

There are plans to give TestFixture approximately the same level of
choices that now exist for methods, so... something like a
FixtureSource, values applied to arguments, etc.

Additionaly, it's likely we will allow injection of values into the
fixture setup method, although how that should interact with
constructor arguments is yet to be decided.

A solution using property injection has not yet been considered. If we
did so, I think I would favor use of a new attribute on the property
rather than overloading the already busy TestFixtureAttribute.
Something like...

[Inject("foo")]
[Inject("bar")]
public string SomeProperty { get; set; }

Of course this introduces lots of questions regarding the interaction
of this feature with use of multiple TestFixture attributes. If we
have 2 TestFixture attributes, does the combination result in two or
four instances of the fixture, for example?

Usually, new features like this are hammered out in discussions on our
mailing list, nunit-discuss, hosted on google. You're welcome to start
the discussion!

Can you help with this problem?

Provide an answer of your own, or ask Roger Kratz for more information if necessary.

To post a message you must log in.