Loading...

nunit-discuss@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

Re: [nunit-discuss] Parameterized testfixture with default ctor Charlie Poole Thu Apr 05 13:00:58 2012

Hi Roger,

I can't see completely discarding the constructor arguments...

1) General backward compatibility for folks who are happy with them.

2) They're pretty much needed for easy use of generic fixtures. If you
eliminated them, then you would have to specify the type argments
explicitly and your injectable properties would need to be of some
fixed type - rather than using one of the type arguments.

I can, however see de-emphasizing their use for non-generic
parameterized fixtures.

Charlie

On Thu, Apr 5, 2012 at 4:47 AM, Roger Kratz <[EMAIL PROTECTED]> wrote:
> How about discarding the injecting stuff from TestFixture all together and
> allow InjectAttribute (or similar name) be placed on either ctor or
> properties?
>
> For ctor injection...
>
> [TestFixture]
> class MyTest
>    [Inject(1, 2)]
>    MyTest(int foo) {}
>
> For prop injection...
>
> [TestFixture]
> class MyTest
>  [Inject(1, 2)]
>  int SomeProperty {get;set;}
>
>
> /Roger
>
>
>
>
> On Tuesday, April 3, 2012 7:03:35 PM UTC+2, charlie wrote:
>>
>> Hi Roger,
>>
>> Thanks for posting this here. It seems to me we should have a feature
>> like this in 3.0, but I'd like to hear what others think.
>>
>> There would be a few issues to work out.
>>
>> 1. What would the syntax look like? Some new attribute on the property
>> is one obvious approach.
>>
>> 2. If you combine the existing constructor injection with propoerty
>> injection, how should that work? For example, what if you coded...
>>
>>    [TestFixture(5, "hello")]
>>    [TestFixture(6, "goodbye")]
>>    public class MyClass(int num, string word)
>>    {
>>       [Inject(1, 2, 3)]
>>       public int SomeProperty { get; set; }
>>
>>       ...
>>    }
>>
>>    How many instances would we create? Of course this may be a
>> pathological example, but we have to deal with it some way.
>>
>> 3. Alternatively, can we figure out some way to keep the property
>> values on the TestFixtureAttribute, without creating a non-default
>> constructor?
>>
>> 4. What about allowing values to be passed to the SetUp or
>> SetUpFixture method? And how would that interact with everything else.
>>
>> Charlie
>>
>>
>> On Tue, Apr 3, 2012 at 4:02 AM, Roger Kratz <@gmail.com> wrote:
>> > (similar question posted here:
>> > https://answers.launchpad.net/nunitv2/+question/189098)
>> >
>> > Hi
>> >
>> > In a pretty big project (~1000 test fixtures) the test fixtures derives
>> > from
>> > a common base class. Because of new requirements I needed to run the
>> > tests
>> > twice, with two different configurations. To accomplish this I used
>> > nunit's
>> > feature "Parameterized test fixture" and declared two testfixture
>> > attributes
>> > on the base class. This worked fine, but led to tedious work adding the
>> > parameterized ctor on all test fixtures.
>> > I've already done this, but I would have had a lot of easier work if
>> > nunit
>> > would have accepted property injection rather than ctor injection. Also,
>> > in
>> > my opinion, this would have led to cleaner test fixtures with no
>> > "disturbing", explicit ctor (even though I must say that I'm
>> > 100% favoring ctor injection rather than accessor injection in "normal"
>> > code).
>> >
>> > Are there any plans to implement something like this in nunit?
>> >
>> > Regards
>> > Roger
>> >
>> > --
>> > You received this message because you are subscribed to the Google
>> > Groups
>> > "NUnit-Discuss" group.
>> > To view this discussion on the web visit
>> > https://groups.google.com/d/msg/nunit-discuss/-/5eO8rtPKgJAJ.
>> > To post to this group, send email to [EMAIL PROTECTED]
>> > To unsubscribe from this group, send email to
>> > [EMAIL PROTECTED]
>> > For more options, visit this group at
>> > http://groups.google.com/group/nunit-discuss?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups
> "NUnit-Discuss" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/nunit-discuss/-/sND_xLc8O4cJ.
>
> To post to this group, send email to [EMAIL PROTECTED]
> To unsubscribe from this group, send email to
> [EMAIL PROTECTED]
> For more options, visit this group at
> http://groups.google.com/group/nunit-discuss?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"NUnit-Discuss" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nunit-discuss?hl=en.