未処理の例外を意図的に生成する単体テストがあります。以下を使用して、未処理の例外 (テストしたい) のハンドラーを配線しました。
AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler;
私のテストは次のとおりです。
LogClient client = new LogClient(); // The handler is wired up in here
Trace.TraceInformation( "About to cause an unhandled divide-by-zero exception." );
for ( int i = 10; i > -10; --i )
{
int j = 100 / i;
Console.WriteLine( "i={0}, j={1}", i, j );
}
Assert.NotNull( client.UnhandledException );
もちろん、例外がスローされ、NUnit がそれをキャッチしてテストに失敗します。追加してみました
[ExpectedException(typeof(DivideByZeroException))]
テストは「合格」しますが、ハンドラーが呼び出されることはなく、Assert.NotNull
実行されることもありません。未処理の例外ハンドラーの単体テストを作成できるかどうか疑問に思っています。任意のポインタをいただければ幸いです。
私はVS 2010でNUnit 2.5.7を使用しています。