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.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.