score:1

Accepted answer

as suggested by @matthewfarwell in the comments i implemented a test rule as per his answer

public static class retry implements testrule {

    private final int retrycount;

    public retry(int retrycount) {
        this.retrycount = retrycount;
    }

    @override
    public statement apply(final statement base,
            final description description) {
        return new statement() {

            @override
            @suppresswarnings("synthetic-access")
            public void evaluate() throws throwable {
                throwable caughtthrowable = null;
                int failurescount = 0;
                for (int i = 0; i < retrycount; i++) {
                    try {
                        base.evaluate();
                    } catch (throwable t) {
                        caughtthrowable = t;
                        system.err.println(description.getdisplayname()
                            + ": run " + (i + 1) + " failed:");
                        t.printstacktrace();
                        ++failurescount;
                    }
                }
                if (caughtthrowable == null) return;
                throw new assertionerror(description.getdisplayname()
                        + ": failures " + failurescount + " out of "
                        + retrycount + " tries. see last throwable as the cause.", caughtthrowable);
            }
        };
    }
}

as a nested class in my test class - and added

@rule
public retry retry = new retry(69);

before my test methods in the same class.

this indeed does the trick - it does repeat the test 69 times - in the case of some exception a new assertionerror, with an individual message containing some statistics plus the original throwable as a cause, gets thrown. so the statistics will be also visible in the junit view of eclipse.


Related Query

More Query from same tag