最近升级到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;
}
Run Code Online (Sandbox Code Playgroud)
但是,我们在访问属性TestContext.CurrentContext.Test.Name时看到NullReferenceExceptions,因为似乎没有正确注册NUnit CallContext.
有没有其他人遇到过这个问题,或者可以建议一种从SetUp确定当前测试名称的替代方法?