Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you're sure you <em>really</em> want to do this: There may be a better way, but this is all I could come up with...</p> <p>JUnit4 has an annotation: <code>@RunWith</code> which lets you override the default Runner for your tests.</p> <p>In your case you would want to create a special subclass of <code>BlockJunit4ClassRunner</code>, and override <code>computeTestMethods()</code> to return tests in the order you want them executed. For example, let's say I want to execute my tests in reverse alphabetical order:</p> <pre><code>public class OrderedRunner extends BlockJUnit4ClassRunner { public OrderedRunner(Class klass) throws InitializationError { super(klass); } @Override protected List computeTestMethods() { List list = super.computeTestMethods(); List copy = new ArrayList(list); Collections.sort(copy, new Comparator() { public int compare(FrameworkMethod o1, FrameworkMethod o2) { return o2.getName().compareTo(o1.getName()); } }); return copy; } }</code></pre> <pre><code>@RunWith(OrderedRunner.class) public class OrderOfTest { @Test public void testA() { System.out.println("A"); } @Test public void testC() { System.out.println("C"); } @Test public void testB() { System.out.println("B"); } }</code></pre> <p>Running this test produces:</p> <pre>C B A</pre> <p>For your specific case, you would want a comparator that would sort the tests by name in the order you want them executed. (I would suggest defining the comparator using something like Google Guava's class <code>Ordering.explicit("methodName1","methodName2").onResultOf(...);</code> where onResultOf is provided a function that converts FrameworkMethod to its name... though obviously you are free to implement that any way you want.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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