Search code examples
c#nunitteardown

How to pass Category value from test to TearDown


I am running a test with the following attributes [TestCase(“First Count”), Category(“Catalog”)]

Later in TearDown I want to get the value "Catalog". I tried:

var cat = (string)TestContext.CurrentContext.Test.Properties.Get("Category");

But as a result - null I also tried to add [Property("value","Catalog")] to the test attributes Still the same result. How else can you do it?


Solution

  • With the syntax you are using, the Category is not applied to the individual test case but to the method as a whole, that is to the (internal) test suite created by NUnit to hold all the test cases for that method.

    To apply a Category to a single test case, use this syntax: [TestCase("FirstCount", Category="Catalog")]

    That said... there could be other problems since you haven't shown the entire TearDown method. If the above doesn't fix it, pelase edit your question to include the full method.