Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>JanakiL, It is a very good question. I tried to find some solution but i didn't manage to find clean solution for this task. I can only propose to do some workaround that eventually will work. So, in order to re-run suite you need to do following steps:</p> <ol> <li><p>You need to create @ClassRule in order to execute whole suite. All Suite you can retry using following code:</p> <p>public class Retrier implements TestRule{</p> <pre><code>private int retryCount; private int failedAttempt = 0; @Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { base.evaluate(); while (retryNeeded()){ log.error( description.getDisplayName() + " failed"); failedAttempt++; } } </code></pre> <p>}</p></li> </ol> <p>retryNeeded() – method that determines whether you need to do retry or not</p> <p>This will retry all tests in your suite. Very important thing that retry will go after @AfterClass method.</p> <p>In case you need to have “green build” after successful retry you need to write a bunch of another gloomy code.</p> <ol> <li>You need to create @Rule that will not allow “publish” failed result. As example:</li> </ol> <p><code> public class FailedRule extends TestWatcher {</p> <pre><code>@Override public Statement apply(final Statement base, final Description description) { return new Statement() { @Override public void evaluate() throws Throwable { List&lt;Throwable&gt; errors = new ArrayList&lt;Throwable&gt;(); try { base.evaluate(); } catch (AssumptionViolatedException e) { log.error("", e.getMessage()); if (isLastRun()) { throw e; } } catch (Throwable t) { log.error("", t.getMessage()); if (isLastRun()) { throw t; } } }; }; } } </code></pre> <p></code></p> <p>isLastRun() – methods to verify whether it is last run and fail test only in case ir is last run.</p> <p>Only last retry needs to be published to mark you test failed and build “red”. 3. And finally in your test class you need do register two rules:</p> <p><code></p> <pre><code>@Rule public FailedRule ruleExample = new FailedRule (); @ClassRule public static Retrier retrier = new Retrier (3); </code></pre> <p></code></p> <p>In the Retrier you can pass count of attempts to retry.</p> <p>I hope that somebody could suggest better solution !</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload