2012-03-12 88 views

回答

0

如果我正確理解你的問題,我認爲你可以使用try-catch語句來捕獲異常,然後用它從那裏

+0

然後,我將不得不爲此在每個測試這正是我想避免 – 2012-03-12 05:33:33

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(); 
    } 
} 
相關問題