在任何异常时停止Fitnesse(Slim)

时间:2016-05-15 21:45:38

标签: fitnesse fitnesse-slim

我们找到了" Fail Fast"对于提高我们基于Fitnesse的大型测试电池的可维护性至关重要的原则。苗条的StopTestException是我们的救世主。

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

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

1 个答案:

答案 0 :(得分:0)

来自灯具的大多数例外可以通过实施StopTestException接口方便地转换为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);
        }
    }
}