0

We've found the "Fail Fast" principle crucial for improving maintainability of our large Fitnesse-based battery of tests. Slim's StopTestException is our saviour.

However, it's very cumbersome and counterproductive to catch and convert any possible exception to those custom StopExceptions. And this approach doesn't work outside of fixtures. Is there a way to tell fitnesse (preferably using Slim test system) to stop test on any error / exception?

Update: corresponding feature request https://github.com/unclebob/fitnesse/issues/935

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27

1 Answers1

0

Most of the exceptions coming from fixtures are possible to conveniently convert to the StopTestException by implementing the FixtureInteraction interface, e.g.:

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);
        }
    }
}
Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27