(MSTest) AssemblyInitialize equivlent?


IUseFixture<T> is the equivalent of SetupFixture in NUnit and ClassInitialize in MSTest. Well, that's not entirely true because in NUnit, If you declare SetUpFixture outside of the namespace in which the tests run, it then will act as setup for the assembly. I would know becuase I had an assembly where I could toggle between MSTest and NUnit freely by giving using aliases such as:


using AssemblyInitialize = NUnit.Framework.SetUpFixtureAttribute;

So how can I get IUseFixture<T> to allow me to share context between all tests in an assembly, not just a class? Is there some other feature of XUnit that will let me do this that I missed?
Closed May 5, 2013 at 2:05 AM by BradWilson
We will support this at the test collection level in v2. We are not planning to do any assembly-wide setup and teardown.


Togakangaroo wrote Dec 11, 2012 at 4:40 PM

Seconded. I realize this goes against the standard unit-testing grain but it's just a matter of being practical.

I have selenium tests so ideally on assembly load I would like to start up iisexpress and on assmebly unload I'd like to shut it down. Doing this on every single test greatly increases the execution time and is simply not practical.

BradWilson wrote Dec 14, 2012 at 1:26 AM

There is no equivalent today.

justinc wrote Dec 15, 2012 at 4:05 PM

Can you just put it into a static constructor?

BradWilson wrote Dec 16, 2012 at 3:57 AM

You can't predict when static constructors are run (only that they have run before you can touch any static members).

There would be no cleanup equivalent, using a static constructor.

RhysC wrote Mar 15, 2013 at 3:28 AM

I'm in the same boat as Togakangaroo, would like to use xunit as it it s what we are using for our unit tests, however not having an assembly wide init makes this difficult (specifically for selenium based tests)