小编Ada*_*ott的帖子

在NUnit 2.5.8中使用TestContext时出现NullReferenceException

最近升级到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确定当前测试名称的替代方法?

c# nunit

5
推荐指数
1
解决办法
959
查看次数

标签 统计

c# ×1

nunit ×1