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-->MyRunner.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>
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.
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.
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.
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.
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:
Please again note my custom test runner is located here: androidTest-->java-->com-->mobile-->myapp-->base-->MyRunner.java
then testInstrumentationRunner
is wrong. The path has to match the location of the file
testInstrumentationRunner "com.mobile.myapp.base.MyRunner"
should do it
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With