与 分包冲突
junit.framework.AssertionFailedError: No tests found in com.livestrong.tracker.test.Test1AuthenticationEspressoTest
Android Espresso not working with Multidex gives “No tests found”
- 只是替换
“testInstrumentationRunner ‘com.android.test.runner.MultiDexTestRunner’”—-“testInstrumentationRunner ‘android.support.test.runner.AndroidJUnitRunner’”
你将会得到另外一个错误
Test running failed: Unable to find instrumentation info for: ComponentInfo
- 正确做法
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)).
- 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.
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