2016-05-15 32 views
0

我们发现“Fail Fast”原则对于改进基于大型Fitnesse电池测试的可维护性至关重要。斯利姆的StopTestException是我们的救星。在任何异常情况下停止Fitnesse(Slim)

但是,捕获并将任何可能的异常转换为自定义StopExceptions是非常麻烦和适得其反的。这种方法不适用于灯具之外。有没有办法告诉fitnesse(最好使用Slim测试系统)来停止测试任何错误/异常?

更新:相应的功能要求https://github.com/unclebob/fitnesse/issues/935

回答

0

大部分从夹具来的异常是可以通过实施FixtureInteraction接口,例如:

public class StopOnException extends DefaultInteraction { 

    @Override 
    public Object newInstance(Constructor<?> constructor, Object... initargs) throws InvocationTargetException, InstantiationException, IllegalAccessException { 
     try { 
      return super.newInstance(constructor, initargs); 
     } catch (Throwable e) { 
      throw new StopTestException("Instantiation failed", e); 
     } 
    } 

    @Override 
    public Object methodInvoke(Method method, Object instance, Object... convertedArgs) throws InvocationTargetException, IllegalAccessException { 
     try { 
      return super.methodInvoke(method, instance, convertedArgs); 
     } catch (Throwable e) { 
      throw new StopTestException(e.getMessage(), e); 
     } 
    } 

    public static class StopTestException extends RuntimeException { 

     public StopTestException(String s, Throwable e) { 
      super(s, e); 
     } 
    } 
} 
方便地转换为 StopTestException
相关问题