I'm trying to run black box(i need to test apk from different project) UI test using Robotium in Android Studio. I created simple app with only 1 activity containing single TextView
with text "Hello World!". So in my test i'll check if text "Hello World!" is present in activity. Package of this app is com.example.apptotest.
For beginning i created integrated test inside this project to check if i use Robotium tests correct. So, i created test class inside androidTest directory. Here is code:
public class SimpleTest extends
ActivityInstrumentationTestCase2<MainActivity> {
private Solo solo;
public SimpleTest() {
super(MainActivity.class);
}
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
public void testCorrectActivity() throws Exception {
Assert.assertTrue(solo.searchText("Hello World!"));
}
}
After executing test i got Tests ran to completion. 1 test passed
. Great! Test is working perfect.
Then i tried to run the same test from another project. I created new project with package com.example.blackboxapptest and added this test class with some changes for targeting to my tested app package:
public class SimpleTest extends
ActivityInstrumentationTestCase2 {
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.example.apptotest.MainActivity";
private static Class launcherActivityClass;
static {
try {
launcherActivityClass = Class
.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}
public SimpleTest() throws ClassNotFoundException {
super(launcherActivityClass);
}
private Solo solo;
public void setUp() throws Exception {
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
solo.finishOpenedActivities();
}
public void testCorrectActivity() throws Exception {
Assert.assertTrue(solo.searchText("Hello World!"));
}
}
But after running this test i got Test running failed: Instrumentation run failed due to 'java.lang.ClassNotFoundException'
After that i added some additional fields to build.gradle
:
testApplicationId "com.example.apptotest"
testInstrumentationRunner "android.test.InstrumentationTestRunner"
into defaultConfig
. After that i got the same exception. Only one thing changed - when i added testApplicationId
running test remove tested app from device and write itself to that package.
Then i checked adb
log during installing test case which i wrote inside the same AppToTest project:
adb push D:\ASProjects\AppToTest\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.apptotest
adb shell pm install -r "/data/local/tmp/com.example.apptotest"
adb push D:\ASProjects\AppToTest\app\build\outputs\apk\app-debug-androidTest-unaligned.apk /data/local/tmp/com.example.apptotest.test
adb shell pm install -r "/data/local/tmp/com.example.apptotest.test"
AndroidTest apk installed with package com.example.apptotest.test
. So i tried to change testApplicationId
inside my BlackBoxAppTest to com.example.apptotest.test
. I got the same exception, but AppToTest wasn't rewrited.
Here is adb log:
adb push D:\ASProjects\BlackBoxAppTest\app\build\outputs\apk\app-debug.apk /data/local/tmp/com.example.blackboxapptest
adb shell pm install -r "/data/local/tmp/com.example.blackboxapptest"
adb push D:\ASProjects\BlackBoxAppTest\app\build\outputs\apk\app-debug-androidTest-unaligned.apk /data/local/tmp/com.example.apptotest.test
adb shell pm install -r "/data/local/tmp/com.example.apptotest.test"
So as i understood i have incorrectly specify the target apk for test.
Also i checked these similar questions: first, second, third, fourth but answers didn't help me.
Can anybody tell me how to specify app for black box testing?
Aucun commentaire:
Enregistrer un commentaire