使用Robotium进行Android Studio黑盒测试
作者:互联网
我正在尝试为一个应用程序编写一个黑盒测试,我只使用Robotium获得APK(无源代码).
文档很差,仅限于Eclipse.我正在试图弄清楚如何在Android Studio上编写这种测试.
到目前为止,我已经创建了一个新项目并修改了依赖项的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'
}
然后我写测试,我把它们放在主文件夹中(因为这是一个测试外部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"));
}
}
我的理解是,为了找到应用程序,我必须修改清单并指向targetPackage.我试过这样的
<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>
但该线上有一个错误
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
显然我错过了一些东西.如何处理APK以测试黑盒测试?我如何参考Robotium的测试内容?
解决方法:
您需要在build.gradle文件中指定测试应用程序.在defaultConfig部分中,添加
testApplicationId "com.external.apptotest"
标签:android,android-testing,robotium 来源: https://codeday.me/bug/20190711/1433865.html