My Espresso tests were running until I had to support multidex.
My build.gradle, I have
minSdkVersion 14
targetSdkVersion 23
multiDexEnabled = true
testInstrumentationRunner "com.android.test.runner.MultiDexTestRunner"
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.1'
androidTestCompile 'com.android.support.test:runner:0.4.1'
androidTestCompile 'com.android.support.test:rules:0.4.1'
dexOptions {
jumboMode true
javaMaxHeapSize "4g"
incremental true
}
@RunWith(AndroidJUnit4.class)
@SmallTest
public class Test1AuthenticationEspressoTest {
@Rule
public ActivityTestRule<WelcomeActivity> mActivityRule = new ActivityTestRule(WelcomeActivity.class);
}
Here is the Error I get
junit.framework.AssertionFailedError: No tests found in com.livestrong.tracker.test.Test1AuthenticationEspressoTest
Any help will be appreciated. Any one has espresso working with multidex ?
I was having this same problem and it turns out you need to build a custom runner that enables MultiDex and extends from the AndroidJUnitRunner. You then need to set that runner as your testInstrumentationRunner in the build.gradle, and as your runner in your run configuration. There is no need to modify the test class (keep the @RunWith(AndroidJunit4.class)
).
Here's a step-by-step of what to do:
Create a class for your custom runner:
package com.bla.bla.bla; // your package
import android.os.Bundle;
import android.support.multidex.MultiDex;
import android.support.test.runner.AndroidJUnitRunner;
public class CustomTestRunner extends AndroidJUnitRunner
{
@Override
public void onCreate(Bundle arguments)
{
MultiDex.install(getTargetContext());
super.onCreate(arguments);
}
}
In your build.gradle, set the runner to your custom runner:
android {
// ...
defaultConfig {
// ...
testInstrumentationRunner "com.bla.bla.bla.CustomTestRunner"
}
}
In your run configuration, make sure the instrumentation runner is also set to the same runner.. Note: This step should not be required on Android Studio 3.x and maybe also some previous versions. This option does not exist anymore.
Using the above, I was able to run Espresso tests on our multi-dex enabled app.
I should note that many other posts on the net regarding this topic, suggest setting your runner to com.android.test.runner.MultiDexTestRunner
and exculde some dependencies in com.android.support:multidex-instrumentation:1.0.1
in your build.gradle. That solution appears to no longer be the case and doesn't work as of gradle 1.5.0. If you have any of that stuff set, then it'll prevent the above from working. See the comments in this stack overflow post for more information.
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