当我想将其用于单个apk测试时,"android.support.test.espresso不存在" [英] 'android.support.test.espresso does not exist' when I want to use it to individual apk test

查看:148
本文介绍了当我想将其用于单个apk测试时,"android.support.test.espresso不存在"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在没有源代码的情况下对Android应用程序执行一些自动测试工作.我发现robotium和espresso都可以完成这项工作,我决定使用espresso,因为它具有Google支持.

I need to do some auto testing jobs to an Android application without its source code. I found both robotium and espresso can do this job, I decided to use espresso because its Google support.

我想用相同的签名对目标apk和espresso测试apk进行签名,目标apk与

I would like to sign both the target apk and espresso test apk with the same signature, the target apk is the same as this sample.

当我开始编码espresso测试apk时,我做了以下工作.

When I start to coding the espresso test apk, I did the following jobs.

Module:app中的build.gradle:

The build.gradle in Module:app:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "tk.deedog.i01test"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:21.0.3'

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

我的I01Test.java的源代码:

The source code of my I01Test.java:

package tk.deedog.i01test;

import android.app.Activity;
import android.test.ActivityInstrumentationTestCase2;

import static android.support.test.espresso.Espresso.onView;
import static android.support.test.espresso.action.ViewActions.click;
import static android.support.test.espresso.matcher.ViewMatchers.withText;


public class I01Test extends ActivityInstrumentationTestCase2 {
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "tk.tubabe.instrustmen101.Instruments101";
    private static Class<?> launcherActivityClass;
    Activity i101Acitvity;

    static {
        try {
            launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public I01Test() {
        super(launcherActivityClass);
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        i101Acitvity = getActivity();
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testButtonClick() {
        onView(withText("Send")).perform(click());
    }
}

当我尝试运行该程序时,Android studio告诉我Error:(6, 44) error: package android.support.test.espresso does not exist.

When I tried to run this program, Android studio told me that Error:(6, 44) error: package android.support.test.espresso does not exist.

推荐答案

我遇到了同样的问题,并通过检查我的项目结构使其正常工作.您的测试是否在src/androidTest下?我必须将文件夹的名称从test重构为androidTest

I had the same issue and got it to work by checking my project structure. Are your tests under src/androidTest ? I had to refactor the name of my folder from test to androidTest

这篇关于当我想将其用于单个apk测试时,"android.support.test.espresso不存在"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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