Is there a way of programatically getting the selected test categories while executing a test? something in the lines of TestContext.Properties["_SELECTCATEGORIES"]
basically i've got test cases which load the test data from a db and as i've got a lot of tests the project is taking a long time to load. Im trying to find a way of having the testCaseSources returning nothing if the category is not selected
UPDATED
There does not appear to be any straightforward method for identifying or loading selected categories in an NUnit test assembly within the NUnit Framework itself..
Using reflection, you could perhaps scan the property Categories
in classes decorated with TestAttribute
or TestFixtureAttribute
. By matching these categories with the one(s) you want to load, you could be able to filter out which tests to load before loading.
And then there is the TestContext.Test.Properties
key _CATEGORIES
(available in NUnit 2.5.7 and later):
[Test]
[Category("Hello")]
public void TestCategory()
{
Assert.IsTrue(((ArrayList)TestContext.CurrentContext.Test.Properties["_CATEGORIES"]).Contains("Hello"));
}
Some more to read on the TestContext
class can be found here. Of course, to solve the problem with this approach would require you to load the entire test assembly and loop over all test cases in beforehand, which is obviously undesirable in your scenario.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With