Reputation: 51
Recently upgraded to NUnit 2.5.8 in order to use the new TestContext functionality. This is so that we can determine the current test name in order to retrieve an attribute:
private T GetAttribute<T>() where T : class
{
return Attribute.GetCustomAttribute(GetType().GetMethod(TestContext.CurrentContext.Test.Name), typeof(T)) as T;
}
However, we are seeing NullReferenceExceptions when accessing the property TestContext.CurrentContext.Test.Name because it seems that the NUnit CallContext is not being registered properly.
Has anyone else encountered this problem, or can suggest an alternative way of determining the current test name from the SetUp?
Upvotes: 5
Views: 990
Reputation: 16407
This isn't an answer to your question, but I came across a similar issue when using TestDriven.NET's xcopy-deployable NUnit Test Runner to use NUnit 2.5.7, and hitting a NullReferenceException
because TestDriven.NET was still running the tests under 2.5.5 (which it ships with) and not the NUnit my project referenced.
The problem turned out to be that I was referencing the nunit.framework.dll
found in NUnit\NUnit-2.5.7.10213\bin\net-2.0
when I needed to be referencing the one found in NUnit\NUnit-2.5.7.10213\bin\net-2.0\framework
. Why there are two copies I have no idea, but pointing to the right DLL made all the difference.
Upvotes: 0