Comment 3 for bug 1098766

Revision history for this message
Charlie Poole (charlie.poole) wrote : Re: [Bug 1098766] Re: Feature Request: AssemblyTearDown Attribute

If the attribute is on a method, then we have to search all methods
to find it. Requiring TestFixtureAttribute isn't a solution for two
reasons:

1) It's already optional, so requiring it in this single case would be
confusing.

2) It already means "This class contains tests" and that's not
what we're talking about here.

NUnit actually already has more functionality in this area than MSTest,
although possibly not so easily discoverable. We allow static or
instance methods and we can initialize and clean up for the whole
assembly or for a particular namespace. Rather complex inheritance
hierarchies can be set up, with the setup and teardown methods
a each level applied in a well-defined order. Many people use
this stuff.

In addition, using the parallel facility of ActionAttributes,
you can define common bits of initialization and cleanup and
apply them to an assembly, suite or test method just by
adding the attribute.

OTOH, having more functionality can make things confusing for
the user and I can see the value of having something with the
word "Assembly" in it applied to a class containing these
SetUp and TearDown methods.

One possibility for an inheritance hierarchy:

SetupFixtureAttribute
   NamespaceSetupAttribute
   AssemblySetupAttribute

Initially, NamespaceSetupAttribute would work just the same
as SetupFixtureAttribute. We would deprecate the latter and
eventually make it an abstract class.

AssemblySetupAttribute would apply at the assembly level
without regard to where the class lives in the namespace
hierarchy.

Within each class, we would consistently use [SetUp] and
[TearDown] to mark the methods to be called.

How does that sound?

Charlie

On Fri, Jan 11, 2013 at 8:55 PM, Rodney Foley <email address hidden> wrote:
> I think you first point would be a great reason to provide an attribute
> call AssemblyTearDown and AssemblySetup.
>
> I am not sure why you are saying it shouldn't involve searching all
> methods of all classes to find the proper methods. I didn't suggest such
> an awful thing. Not sure why it would, that is the purpose of the
> attributes I would think, and it can require that a class has a
> TestFixture attribute to make it simpler.
>
> Basically what I am asking for is for how AssemblyCleanup works in
> MSTest. All the rules/restricts I mention are how it works in MSTest
> and it seems a safe approach and made sense.
>
> I will look at how you suggest as it will work as it would be better
> than the hack I had to do to port this from an MSTest project to NUnit
> that had used AssemblyCleanup.
>
> Thanks for the HOW TO and I hope you make this functionality a little
> more obvious and intuitive in the future.
>
> --
> You received this bug notification because you are subscribed to NUnit
> Framework.
> https://bugs.launchpad.net/bugs/1098766
>
> Title:
> Feature Request: AssemblyTearDown Attribute
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/nunit-3.0/+bug/1098766/+subscriptions