简体   繁体   English

使用Robotium进行Android Studio黑盒测试

[英]Android Studio black box testing with Robotium

I'm trying to write a black box test for an application of which i only have the APK (no source code) using Robotium. 我正在尝试为一个应用程序编写一个黑盒测试,我只使用Robotium获得APK(无源代码)。 The documentation is very poor and limited to Eclipse. 文档很差,仅限于Eclipse。 I'm trying to figure out how to write this kind of tests on Android Studio. 我正在试图弄清楚如何在Android Studio上编写这种测试。 So far I've created a new Project and modified the gradle file for the dependancies 到目前为止,我已经创建了一个新项目并修改了依赖项的gradle文件

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.crysis.myautomatedtest"
        minSdkVersion 18
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

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

    compile 'com.jayway.android.robotium:robotium:5.4.1'
    compile 'com.jayway.android.robotium:robotium-solo:5.4.1'
}

then i write the tests and I put them in the main folder (since this is a test-only project that test an external apk) 然后我写测试,我把它们放在主文件夹中(因为这是一个测试外部apk的测试项目)

package com.crysis.myautomatedtest;

import android.test.ActivityInstrumentationTestCase2;
import android.widget.EditText;

import com.robotium.solo.Solo;

public class RobotiumTest extends ActivityInstrumentationTestCase2 {
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.external.apptotest.LoginActivity";
    private static Class launcherActivityClass;
    static {
        try {
            launcherActivityClass = Class
                    .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public RobotiumTest() throws ClassNotFoundException {
        super(launcherActivityClass);
    }
    private Solo mDevice;

    @Override
    public void setUp() throws Exception {
        mDevice = new Solo(getInstrumentation(), getActivity());
    }

    @Override
    public void tearDown() throws Exception {
        mDevice.finishOpenedActivities();
    }

    public void testLogin() {
        mDevice.clearEditText((EditText)mDevice.getView("id/username"));
        mDevice.enterText((EditText) mDevice.getView("id/username"), "Test");

        assertTrue("Problem asserting text", mDevice.searchText("Test"));
    }
}

It's my understanding that in order to find the app I have to modify the manifest and point to a targetPackage. 我的理解是,为了找到应用程序,我必须修改清单并指向targetPackage。 I tryed like this 我试过这样的

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.crysis.myautomatedtest">

    <application android:allowBackup="true" android:label="@string/app_name"
        android:icon="@mipmap/ic_launcher" android:theme="@style/AppTheme">

    </application>

    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.external.apptotest" />

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

</manifest>

But there is an error on that line that states 但该线上有一个错误

Cannot resolve symbol 'com.external.apptotest' (that is the package of the app to test installed on the device) Validates resource references inside Android XML file 无法解析符号'com.external.apptotest'(即要在设备上安装的应用程序包)验证Android XML文件中的资源引用

Clearly I'm missing something. 显然我错过了一些东西。 How do I handle the APK to test in black box testing? 如何处理APK以测试黑盒测试? How do I gave a reference to what to test to Robotium? 我如何参考Robotium的测试内容?

You need to specify the test application in the build.gradle file. 您需要在build.gradle文件中指定测试应用程序。 In defaultConfig section, add 在defaultConfig部分中,添加

testApplicationId "com.external.apptotest"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM