无法与Multidex配合使用的Android Espresso会给出“未找到测试" [英] Android Espresso not working with Multidex gives "No tests found"

查看:138
本文介绍了无法与Multidex配合使用的Android Espresso会给出“未找到测试"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Espresso测试一直在进行,直到我必须支持multidex.

My Espresso tests were running until I had to support multidex.

我的build.gradle,我有

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
    }

Test1AuthenticationEspressoTest

@RunWith(AndroidJUnit4.class)
@SmallTest
public class Test1AuthenticationEspressoTest {
    @Rule
    public ActivityTestRule<WelcomeActivity> mActivityRule = new  ActivityTestRule(WelcomeActivity.class);

}

这是我得到的错误

junit.framework.AssertionFailedError:在以下位置未找到测试 com.livestrong.tracker.test.Test1AuthenticationEspressoTest

junit.framework.AssertionFailedError: No tests found in com.livestrong.tracker.test.Test1AuthenticationEspressoTest

任何帮助将不胜感激.任何人都可以使用multidex制作意式浓缩咖啡吗?

Any help will be appreciated. Any one has espresso working with multidex ?

推荐答案

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

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)).

这是逐步执行的操作:

  1. 为您的自定义跑步者创建一个类:

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

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

  • In your build.gradle, set the runner to your custom runner:

    android {
        // ...
        defaultConfig {
            // ...
            testInstrumentationRunner "com.bla.bla.bla.CustomTestRunner"
        }
    }
    

  • 在您的运行配置中,确保仪器运行器也设置为同一运行器. 注意:在Android Studio 3.x上,甚至某些以前的版本中,都不需要执行此步骤.此选项已不存在.

  • 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.

    使用上述方法,我能够在启用了Multi-dex的应用程序上运行Espresso测试.

    Using the above, I was able to run Espresso tests on our multi-dex enabled app.

    我应该注意网上有关该主题的许多其他文章,建议将运行器设置为com.android.test.runner.MultiDexTestRunner并排除build.gradle中com.android.support:multidex-instrumentation:1.0.1中的某些依赖项.从gradle 1.5.0开始,该解决方案似乎不再适用,并且不再起作用.如果您有任何设置,那么它将阻止以上操作.请参阅此堆栈溢出文章 a>有关更多信息.

    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.

    这篇关于无法与Multidex配合使用的Android Espresso会给出“未找到测试"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆