Hi Mark,
> Is it better to use a [Setup] attribute over a constructor?
Yes. Or more precisely to use [SetUp] or [TestFixtureSetUp],
depending on the desired semantics.
> If so why? Better exception reporting/handling? Symmetry with
> the Teardown?
Those are two reasons, but not the most important:
* NUnit may need to construct your class more than once.
For example, this happens when you use a method of the
same class to generate the tests.
* NUnit provides no special guarantee of the lifetime
of objects of your fixture type. It could (in future)
cache them and reuse them at will.
* Currently, NUnit only constructs one fixture object for
use with each test method, so the proper comparison is
really between constructor and [TestFixtureSetUp]
> I ask because I find the use of initializers so much more
> compact than the typical setup block and before I start
> introducing a new team to my habits I thought I would check
> my assumptions.
I agree, and I would like to work toward a version where
this very natural approach doesn't cause problems. But
that's not so at present. :-(
My own experience is that the problems, while rare, are
incredibly time-consuming when they occur in a team. I
guess that's precisely because it "seems" that the
constructor could do the job.
If you wanted to teach use of the constructor for
initialization, you would also have to provide the
team with a set of exception cases, for which they
must not use it. I have learned that this approach
confuses them even more. :-)
Charlie