Background
An NUnit framework extension that I'm working on needs to know the outcome/result of each test from within an ITestAction attribute, like so:
public class MyFrameworkExtensionAttribute : Attribute, ITestAction
{
public void BeforeTest(ITest test)
{ /* Omitted, not relevant to this question */ }
public void AfterTest(ITest test)
{
var result = TestContext.CurrentContext.Result;
var resultIsSuccess = result.Outcome.Status == TestStatus.Passed;
// Then go on to do stuff with that resultIsSuccess variable
}
}
Note the first line in the AfterTest method; I'm using a static reference: TestContext.CurrentContext. The ITest interface doesn't expose the result of the test, so it seems test context is the only way.
Question
And now my question - because NUnit 3.x includes functionality to run tests in parallel, via ParallelizableAttribute - I'm wondering: Is it safe to use that static reference to the current test context? Are there any thread-safety concerns I should be worried about here? Is there a better/more robust way to get the test outcome without resorting to a static reference?
I'm using NUnit framework 3.7.1 in case it matters.