我的Espresso测试一直在运行,直到我不得不支持multidex。
我的build.gradle,我有
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
}
Test1AuthenticationEspressoTest
@RunWith(AndroidJUnit4.class)
@SmallTest
public class Test1AuthenticationEspressoTest {
@Rule
public ActivityTestRule<WelcomeActivity> mActivityRule = new ActivityTestRule(WelcomeActivity.class);
}
下面是我得到的错误
com.livestrong.tracker.test.Test1AuthenticationEspressoTest中未找到
junit.framework.AssertionFailedError:未找到测试
任何帮助都将不胜感激。有没有人用浓缩咖啡和multidex一起工作?
发布于 2016-02-05 08:14:51
我也遇到了同样的问题,事实证明你需要构建一个自定义运行器来启用MultiDex并从AndroidJUnitRunner扩展。然后,您需要在build.gradle中将该runner设置为您的testInstrumentationRunner,并在run配置中将其设置为runner。不需要修改测试类(保留@RunWith(AndroidJunit4.class)
)。
下面是一步一步要做的事情:
package com.bla.bla.bla;//您的包导入android.os.Bundle;导入android.support.multidex.MultiDex;导入CustomTestRunner公共类扩展包{ @Override public android.os.Bundle onCreate(捆绑包参数){ MultiDex.install(getTargetContext());super.onCreate( arguments);}}
android { // ...defaultConfig { // ...testInstrumentationRunner“com.bla.CustomTestRunner”}}运行配置中的
使用上面的代码,我可以在我们的支持多重索引的应用程序上运行Espresso测试。
我应该注意到网络上关于这个主题的许多其他帖子,建议将您的runner设置为com.android.test.runner.MultiDexTestRunner
,并在build.gradle中排除com.android.support:multidex-instrumentation:1.0.1
中的一些依赖项。这种解决方案似乎不再是这种情况,从gradle 1.5.0开始也不再有效。如果你有任何这样的东西设置,那么它将阻止上面的工作。有关详细信息,请参阅this stack overflow post中的注释。
https://stackoverflow.com/questions/34645537
复制相似问题