首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android Espresso不能与Multidex一起工作给出“未找到测试”

Android Espresso不能与Multidex一起工作给出“未找到测试”
EN

Stack Overflow用户
提问于 2016-01-07 08:45:23
回答 1查看 4.7K关注 0票数 20

我的Espresso测试一直在运行,直到我不得不支持multidex。

我的build.gradle,我有

代码语言:javascript
复制
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

代码语言:javascript
复制
@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一起工作?

EN

回答 1

Stack Overflow用户

发布于 2016-02-05 08:14:51

我也遇到了同样的问题,事实证明你需要构建一个自定义运行器来启用MultiDex并从AndroidJUnitRunner扩展。然后,您需要在build.gradle中将该runner设置为您的testInstrumentationRunner,并在run配置中将其设置为runner。不需要修改测试类(保留@RunWith(AndroidJunit4.class))。

下面是一步一步要做的事情:

  1. 为您的自定义runner创建一个类:

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);}}

  • 在build.gradle中,将运行器设置为您的自定义运行器:

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中的注释。

票数 42
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34645537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档