在任何异常情况下停止Fitnesse(Slim)



我们发现"快速故障"原则对于提高基于Fitnesse的大型测试组的可维护性至关重要。Slim的StopTestException是我们的救星。

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

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

大多数来自fixture的异常都可以通过实现FixtureInteraction接口方便地转换为StopTestException,例如:

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);
        }
    }
}

最新更新