I'm trying to write a black box test for an application of which i only have the APK (no source code) using Robotium. The documentation is very poor and limited to Eclipse. I'm trying to figure out how to write this kind of tests on Android Studio. So far I've created a new Project and modified the gradle file for the dependancies
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)
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. 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
Clearly I'm missing something. How do I handle the APK to test in black box testing? How do I gave a reference to what to test to Robotium?
You need to specify the test application in the build.gradle file. In defaultConfig section, add
testApplicationId "com.external.apptotest"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.