2011-02-02 58 views
0

從我所知道的情況來看,包含插件的程序集必須位於C:\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\addins中。我認爲我的程序集正在加載,因爲我必須先關閉NUnit-gui,然後才能替換addins目錄中的程序集。然而,問題是我沒有看到外掛的任何影響(沒有事件處理程序被調用)如何驗證NUnit Addin已被加載?

因此如何驗證我的外掛程序是否已加載?我很喜歡用調試器,但我會非常樂意使用打印線調試。當我嘗試做File.WriteAllText()插件未能加載,但沒有理由。另外,我該如何調試加載過程?

NUnit docs很有幫助,但在可擴展性方面它們是最好的,而NUnit.Core中的類沒有任何智能感知。

回答

1

您應該使用一些跟蹤庫,如one,您可以下載here。 現在你可以使用語句類似這樣的裝點您的相關方法:

using ApiChange.Infrastructure; 
class MyAddin 
{ 
    static TypeHashes myType = new TypeHashes(typeof(MyAddin); 

    void RelevantMethod() 
    { 
     using (Tracer t = new Tracer(myType, "RelevantMethod")) 
     { 
      .... 
      if(bLoaded == false) 
      t.Error("Could not load adding because of {0}", reason); 
     } 
    } 
} 

然後,您可以啓用通過環境變量_TRACE跟蹤

set _Trace=debugoutput 

DebugOutput可以使用Sysinternals的工具DbgView被視爲(無附加只需啓動它並觀察痕跡)。 或者你跟蹤到一個文件

set _Trace=file 

跟蹤文件所在位置的可執行文件是如Nunit.exe.txt。如果您將_TRACE設置爲某個隨機字符串,它將跟蹤控制檯和OutputDebugString的幫助,爲您提供幫助。

爲什麼這個跟蹤庫?它實際上是唯一一個能夠在你的方法被遺留時追蹤任何異常的人。當方法包含像上面那樣使用語句進行跟蹤時,這會起作用。如果NUnit選擇忽略你的插件實際上是你的錯誤,那麼你現在就可以發現它。 輸出將是這樣的:

* ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception 18:57:46.665 03064/05180 < {{> ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod 18 :57:46.668 03064/05180 < {{> ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod 18:57:46.670 03064/05180 <}} < ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod拋出異常:System.NotImplementedException:喜這是ApiChange的一個錯誤 .IntegrationTests.Diagnostics.TracingTests.FaultyMethod() 在ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod() 在ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeMethod() 在ApiChange.IntegrationTests.Diagnostics.TracingTests.Demo_Show_Leaving_Trace_With_Exception() 18:57:46.670 03064/05180 <}} < ApiChange.IntegrationTests.Diagnostics.TracingTests.SomeOtherMethod時間2ms的 18:57:46.689 03064/05180 <}} < ApiChange.IntegrationTests.Diagnostics.TracingTests。SomeMethod Duration 24ms

這應該很容易找出爲什麼你的Addin沒有被使用。而且你不需要調試器;-)。

你的, 阿洛伊斯·克勞斯

+0

哇,這聽起來非常有幫助。我會試試看... – kelloti 2011-02-06 21:36:07