最近升级到NUnit 2.5.8,以便使用新的TestContext功能。这样我们就可以确定当前测试名称,以便检索属性:
private T GetAttribute<T>() where T : class
{
return Attribute.GetCustomAttribute(GetType().GetMethod(TestContext.CurrentContext.Test.Name), typeof(T)) as T;
}
然而,当访问属性TestContext.CurrentContext.Test.Name时,我们遇到了NullReferenceExceptions问题,因为似乎NUnit CallContext没有被正确注册。
是否有其他人遇到过这个问题,或者可以建议另一种从SetUp确定当前测试名称的方法?