Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

espresso - how to declare path for custom test runner

I have created a custom test runner for espresso and it looks like this:

    public class MyRunner extends AndroidJUnitRunner {
  @Override
  public Application newApplication(ClassLoader cl, String className, Context context)
      throws Exception {
    return super.newApplication(cl, MyCustomEspressoApplication.class.getName(), context);
  }
}

i have placed the class inside of the androidTest folder. Is that ok ?

Now i went to the gradle file to update the test runner and i put in this:

testInstrumentationRunner "com.mobile.myapp.base.MyRunner"

(is this path ok ? remember i put it in the androidTest folder).

and one of my tests classes structure looks like this:

    @RunWith(AndroidJUnit4.class)

public class AuthenticationActivityTest {
//....

@Test
   public void signupWithFacebook() {//...}
}

but when i run the test android studio says it cant find the test runner. here is the exact error i get:

   Test running failed: Unable to find instrumentation info for:
 ComponentInfo{com.mobile.myapp.labs.test/android.support.test.runner.AndroidJUnitRunner}

Please again note my custom test runner is located here: androidTest-->java-->com-->mobile-->myapp-->base-->MyRun‌​ner.java

UPDATE: below is the custom testrunner i am trying to use:

    package com.mobile.myapp.base;

import android.support.test.runner.AndroidJUnitRunner;

import com.squareup.rx2.idler.Rx2Idler;

import io.reactivex.plugins.RxJavaPlugins;



public class MyRunner extends AndroidJUnitRunner {
    @Override public void onStart() {
        RxJavaPlugins.setInitComputationSchedulerHandler(
                Rx2Idler.create("RxJava 2.x Computation Scheduler"));
        // etc...

        super.onStart();
    }
}

when i check the android manifest generated i see this :

<instrumentation
       android:name="com.mobile.myapp.base.MyRunner"
       android:functionalTest="false"
       android:handleProfiling="false"
       android:label="Tests for com.mobile.myapp.labs"
       android:targetPackage="com.mobile.myapp.labs" />

   <application>
       <uses-library android:name="android.test.runner" />
   </application>
like image 529
j2emanue Avatar asked Oct 16 '17 09:10

j2emanue


People also ask

Why do you use AndroidJUnitRunner when running UI tests?

Why do you use the AndroidJUnitRunner when running UI tests? The test runner facilitates loading your test package and the app under test onto a device or emulator, runs the test, and reports the results. The test runner creating screenshots of each screen that displayed while tests are executed.

How do you record an espresso test?

Record UI interactionsClick Run > Record Espresso Test. In the Select Deployment Target window, choose the device on which you want to record the test. If necessary, create a new Android Virtual Device. Click OK.

What is testInstrumentationRunner Androidx test runner AndroidJUnitRunner?

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" (from ToDoTests/build.gradle) This tells Android how to run our JUnit instrumented tests. JUnit uses “runner” classes for this role, and androidx. test.

What is Androidx test core?

AndroidX Test is a collection of Jetpack libraries that lets you run tests against Android apps. It also provides a series of tools to help you write these tests. For example, AndroidX Test provides JUnit4 rules to start activities and interact with them in JUnit4 tests.


2 Answers

finally figured this out after hours of effort. This combination got it it work:

uninstall the current application. delete all testing configurations in run area by clicking on run -->edit configurations and deleting the entire instrumentation testing configurations and then starting again. Here is an image:

enter image description here

like image 159
j2emanue Avatar answered Nov 10 '22 22:11

j2emanue


Please again note my custom test runner is located here: androidTest-->java-->com-->mobile-->myapp-->base-->MyRun‌​ner.java

then testInstrumentationRunner is wrong. The path has to match the location of the file

testInstrumentationRunner "com.mobile.myapp.base.MyRunner"

should do it

like image 44
Blackbelt Avatar answered Nov 10 '22 23:11

Blackbelt