2012-03-12 10 views

答えて

0

は、私はあなたがして例外をキャッチするのtry-catchステートメントを使用して例外オブジェクトではありませんが

+0

その後、私は私は避けるようにしようとしているものですすべてのテストでこれをしなければならないでしょう –

2

から、それを使用することができることを考えますスタックトレースなどをログから抽出することは可能です(https://github.com/Gallio/Gallio-VS2011-Integration/blob/master/MbUnitAdapter/MbUnitAdapter/StackTraceHunter.cs参照)。

おそらく行うための最善のことは、サブクラスTestAttributeです:

public class InspectExceptionAttribute : TestAttribute 
{ 
    protected override void Execute(PatternTestInstanceState state) 
    { 
     try 
     { 
      base.Execute(state); 
     } 
     catch (Exception e) 
     { 
      // do something with e 
     } 
    } 
} 

public class InspectExceptionTests 
{ 
    [InspectException] 
    public void With_interceptor() 
    { 
     throw new NotImplementedException(); 
    } 

    [Test] 
    public void Without_interceptor() 
    { 
     throw new NotImplementedException(); 
    } 
} 
関連する問題