Reputation: 1531
Is there a way to find out programmatically what TestCategory is running in a method marked [AssemblyInitialize]?
I want to do some configuration specific to a certain test category.
Upvotes: 3
Views: 2006
Reputation: 4711
No, TestCategory is only used by MSTest to select which tests to run. The only information available at test runtime is exposed through the TestContext class.
One (admittedly nasty) approach is to make a static class or method which can lazily perform the configuration, and invoke this from each test method with the designated category. But beware, if you manipulate shared global state it can cause unpredictable behaviour when MSTest schedules tests in different sequences.
When writing integration tests, I find it is better to have strong dependency and configuration cohesion in each assembly, even if this means you have many small test assemblies. In other words, all tests in a given assembly use the same setup and have the same dependencies. This reduces the chance that a previous test changed some global state (leading to intermittent instabilities). It also often makes tests execute faster, since different categories of test can't repeatedly make conflicting configuration changes.
Upvotes: 3