(4.5.5)Expresso 疑难

与 分包冲突

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

  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);
    }
}
  1. In your build.gradle, set the runner to your custom runner:
android {
    // ...
    defaultConfig {
        // ...
        testInstrumentationRunner "com.bla.bla.bla.CustomTestRunner"
    }
}
  1. 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值