【问题标题】:How to Implement linkedin's TestButler library in Espresso test如何在 Espresso 测试中实现 linkedin 的 TestButler 库
【发布时间】:2017-02-27 10:03:08
【问题描述】:

我正在尝试实现TestButler 库来消除模拟器的脆弱性。 提到的步骤之一是将以下代码添加到测试运行器类:

package com.linkedin.util;

import android.os.Bundle;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnitRunner;
import com.linkedin.android.testbutler.TestButler;

public class ExampleTestRunner extends AndroidJUnitRunner {

@Override
public void onStart() {
    TestButler.setup(InstrumentationRegistry.getTargetContext());

    super.onStart();
}

@Override
public void finish(int resultCode, Bundle results) {
    TestButler.teardown(InstrumentationRegistry.getTargetContext());

    super.finish(resultCode, results);
}
}

我不确定在哪里插入此代码,因为在我的测试用例中我使用的是 @RunWith(AndroidJUnit4.class)

【问题讨论】:

    标签: android junit4 android-espresso


    【解决方案1】:

    你应该把它放在 androidbuild.gradle -> defaultConfig

    testInstrumentationRunner 'com.linkedin.util.ExampleTestRunner'
    

    覆盖默认运行器

    【讨论】:

    • 这样做会出现错误:测试运行失败:无法找到以下检测信息:ComponentInfo{test_package_path/android.support.test.runner.AndroidJUnitRunner}
    • 你能分享你的 build.gradle 文件吗?你也是从 Android Studio 运行这个吗?
    • 是的,我正在从 android studio 运行它。此外,在我的 build.gradle 文件中,我只是简单地注释了 testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner' 并在此处添加了新的类路径。
    • 您是否已将 ExampleTestRunner 复制到项目中的此包中?还请检查 Android Studio 运行配置以测试它是否将运行器更新为新的运行器。
    • 谢谢。它成功了。我没有更改 Android Studio 中的运行配置。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-31
    • 2016-09-24
    • 1970-01-01
    • 1970-01-01
    • 2016-03-07
    • 2014-01-08
    相关资源
    最近更新 更多