enable Espresso tests to auto run, now there are x86 emulators
This commit is contained in:
		
							parent
							
								
									22773f3de3
								
							
						
					
					
						commit
						3c185d6d64
					
				@ -21,8 +21,8 @@ import org.fdroid.fdroid.views.main.MainActivity;
 | 
			
		||||
import org.hamcrest.Matchers;
 | 
			
		||||
import org.junit.After;
 | 
			
		||||
import org.junit.AfterClass;
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.BeforeClass;
 | 
			
		||||
import org.junit.Ignore;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.junit.runner.RunWith;
 | 
			
		||||
@ -45,29 +45,36 @@ import static android.support.test.espresso.matcher.ViewMatchers.withText;
 | 
			
		||||
import static org.hamcrest.Matchers.allOf;
 | 
			
		||||
import static org.hamcrest.Matchers.not;
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
import static org.junit.Assume.assumeTrue;
 | 
			
		||||
 | 
			
		||||
@Ignore
 | 
			
		||||
@RunWith(AndroidJUnit4.class)
 | 
			
		||||
public class MainActivityEspressoTest {
 | 
			
		||||
    public static final String TAG = "MainActivityEspressoTest";
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Emulators older than {@code android-25} seem to fail at running Espresso tests.
 | 
			
		||||
     * <p>
 | 
			
		||||
     * ARM emulators are too slow to run these tests in a useful way.  The sad
 | 
			
		||||
     * thing is that it would probably work if Android didn't put up the ANR
 | 
			
		||||
     * "Process system isn't responding" on boot each time.  There seems to be no
 | 
			
		||||
     * way to increase the ANR timeout.
 | 
			
		||||
     */
 | 
			
		||||
    private static boolean canRunEspresso() {
 | 
			
		||||
        if (Build.VERSION.SDK_INT < 25
 | 
			
		||||
                || (Build.SUPPORTED_ABIS[0].startsWith("arm") && isEmulator())) {
 | 
			
		||||
            Log.e(TAG, "SKIPPING TEST: ARM emulators are too slow to run these tests in a useful way");
 | 
			
		||||
            return false;
 | 
			
		||||
        }
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @BeforeClass
 | 
			
		||||
    public static void classSetUp() {
 | 
			
		||||
        Log.i(TAG, "setUp " + isEmulator() + " " + Build.SUPPORTED_ABIS[0]);
 | 
			
		||||
        if (Build.SUPPORTED_ABIS[0].startsWith("arm") && isEmulator()) {
 | 
			
		||||
            Log.e(TAG, "SKIPPING TEST: ARM emulators are too slow to run these tests in a useful way");
 | 
			
		||||
            org.junit.Assume.assumeTrue(false);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        IdlingPolicies.setIdlingResourceTimeout(10, TimeUnit.MINUTES);
 | 
			
		||||
        IdlingPolicies.setMasterPolicyTimeout(10, TimeUnit.MINUTES);
 | 
			
		||||
        if (!canRunEspresso()) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
 | 
			
		||||
        try {
 | 
			
		||||
            UiDevice.getInstance(instrumentation)
 | 
			
		||||
@ -105,6 +112,11 @@ public class MainActivityEspressoTest {
 | 
			
		||||
                || "google_sdk".equals(Build.PRODUCT);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Before
 | 
			
		||||
    public void setUp() {
 | 
			
		||||
        assumeTrue(canRunEspresso());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Placate {@link android.os.StrictMode}
 | 
			
		||||
     *
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user