Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You do have a <a href="http://junit.org/junit/javadoc/4.5/org/junit/runner/manipulation/Sortable.html" rel="nofollow noreferrer">Sortable</a> but I can't see how you would use it.</p> <p>You could extend <a href="http://junit.org/junit/javadoc/4.5/org/junit/runners/BlockJUnit4ClassRunner.html" rel="nofollow noreferrer">BlockJUnit4ClassRunner</a> and have <a href="http://junit.org/junit/javadoc/4.5/org/junit/runners/BlockJUnit4ClassRunner.html#computeTestMethods()" rel="nofollow noreferrer">computeTestMethods</a>() return a randomized copy of super.computeTestMethods(). Then use the @<a href="http://junit.org/junit/javadoc/4.5/org/junit/runner/RunWith.html" rel="nofollow noreferrer">RunWith</a> to set that as the runner to use.</p> <p>e.g.</p> <pre class="lang-js prettyprint-override"><code>package com.stackoverflow.mlk; import java.util.Collections; import org.junit.runners.BlockJUnit4ClassRunner; import org.junit.runners.model.InitializationError; public class RandomBlockJUnit4ClassRunner extends BlockJUnit4ClassRunner { public RandomBlockJUnit4ClassRunner(Class&lt;?&gt; klass) throws InitializationError { super(klass); } protected java.util.List&lt;org.junit.runners.model.FrameworkMethod&gt; computeTestMethods() { java.util.List&lt;org.junit.runners.model.FrameworkMethod&gt; methods = super.computeTestMethods(); Collections.shuffle(methods); return methods; } } </code></pre> <p>Then</p> <pre class="lang-js prettyprint-override"><code>@RunWith(com.stackoverflow.mlk.RandomBlockJUnit4ClassRunner.class) public class RandomOrder { @Test public void one() { } @Test public void two() { } @Test public void three() { } } </code></pre>
 

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