Android Studio Espresso测试错误:空测试套件 [英] Android Studio Espresso Testing Error: Empty Test Suite

查看:104
本文介绍了Android Studio Espresso测试错误:空测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试在Android Studio中执行测试时,我始终遇到以下错误:测试运行失败:无法找到以下组件的检测信息:ComponentInfo {.test/android.support.test.runner.AndroidJUnitRunner}

I keep running into the following error when trying to execute my tests in Android Studio: Test running failed: Unable to find instrumentation info for: ComponentInfo{.test/android.support.test.runner.AndroidJUnitRunner}

我的测试类位于androidTest/java目录中,并具有一个构造函数.我的build.gradle也正确.感谢您的帮助.

My test class is in the androidTest/java directory and has a constructor. My build.gradle is correct too. Any help is appreciated.

测试类

@RunWith(AndroidJUnit4.class)
@LargeTest
public class AndroidUITests extends ActivityInstrumentationTestCase2<UserActivity>{

    private UserActivity userActivity;

    public AndroidUITests() {
        super(UserActivity.class);
    }


    @Before
    public void setUp() throws Exception {
        super.setUp();
        injectInstrumentation(InstrumentationRegistry.getInstrumentation());
        userActivity = getActivity();
    }

    @Test
    public void testPhoneIconIsDisplayed() {
        // When the phone_icon view is available,
        // check that it is displayed.
        onView(ViewMatchers.withId(R.id.groupCreate)).perform(click())
                .check(matches(withText("Enter a name")));
    }
}

app/build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        testInstrumentationRunner
        "android.support.test.runner.AndroidJUnitRunner"
    }

    packagingOptions {
        exclude 'LICENSE.txt'
    }
}

dependencies {
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}

推荐答案

您必须更新测试编辑配置",并包括AndroidJUnitRunner作为检测运行器.

You have to update the test "Edit Configuration" and include the AndroidJUnitRunner as the instrumentation runner.

我在此视频中找到了解决方案: https://youtu.be/TGU0B4qRlHY?t=9m36s

I found the solution in this video: https://youtu.be/TGU0B4qRlHY?t=9m36s

已更新

添加@loeschg建议: 在运行测试之前,请确保检查logcat日志以确保没有引起任何问题(崩溃).尽管设置了正确的测试运行器,但@BeforeClass块中的错误代码仍可能在Android Studio中导致显示"Empty Test Suite"消息.

Adding what @loeschg suggest: Make sure you check the logcat logs to ensure something isn't causing issues (crash) before the test is even run. Bad code in the @BeforeClass block could resulted in the "Empty Test Suite" message in Android Studio despite having properly set the test runner.

这篇关于Android Studio Espresso测试错误:空测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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