最近升級到NUnit 2.5.8以使用新的TestContext功能。這是爲了讓我們可以判斷目前的測試名稱,以便檢索屬性:在NUnit中使用TestContext時的NullReferenceException 2.5.8
private T GetAttribute<T>() where T : class
{
return Attribute.GetCustomAttribute(GetType().GetMethod(TestContext.CurrentContext.Test.Name), typeof(T)) as T;
}
然而,訪問屬性TestContext.CurrentContext.Test.Name當我們看到NullReferenceException異常,因爲它似乎是NUnit的CallContext中是沒有正確註冊。
是否有其他人遇到過這個問題,或者可以建議從SetUp中確定當前測試名稱的替代方法?
你如何運行測試?您是否使用了可能是問題的特定測試跑步者? – 2010-11-10 15:04:09
由NUnit GUI轉輪和Resharper轉輪展出。 – 2010-11-10 22:26:33