簡體   English   中英

在NUnit 2.5.8中使用TestContext時出現NullReferenceException

[英]NullReferenceException when using TestContext in NUnit 2.5.8

最近升級到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確定當前測試名稱的替代方法?

這不是你的問題的答案,但我在使用TestDriven.NET的xcopy-deployable NUnit Test Runner使用NUnit 2.5.7並遇到NullReferenceException時遇到了類似的問題,因為TestDriven.NET仍在2.5下運行測試.5(它隨附),而不是我的項目引用的NUnit。

原來,這個問題是,我是引用nunit.framework.dll中發現的NUnit\\NUnit-2.5.7.10213\\bin\\net-2.0 ,當我需要被引用的一個中發現的NUnit\\NUnit-2.5.7.10213\\bin\\net-2.0\\framework 為什么有兩個副本我不知道,但指向正確的DLL使所有的差異。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM