Test order with espresso

mr. Nutscracker picture mr. Nutscracker · Aug 14, 2014 · Viewed 17.7k times · Source

Is there a way to set test running order in android?
I use Espresso framework and need to test a lot of activities and transitions between them. I want to write different test for those activities, but I need a specific order for running those tests.

Answer

Shivaraj Patil picture Shivaraj Patil · Sep 30, 2015

espresso set running order of tests

From Junit 4.11 comes with @FixMethodOrder annotation. Instead of using custom solutions just upgrade your junit version and annotate test class with FixMethodOrder(MethodSorters.NAME_ASCENDING). Check the release notes for the details.

Here is a sample:

import org.junit.runners.MethodSorters;

import org.junit.FixMethodOrder;
import org.junit.Test;

@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SampleTest {

   @Test
   public void A_firstTest() {
      System.out.println("first");
   }

   @Test
   public void B_secondTest() {
      System.out.println("second");
   }
}