2012-03-12 83 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(); 
    } 
} 
相关问题