- Create one workspace or Directory named as “Workspace_Robotium”
- Start eclipse.
- Choose workspace.
- New -> Project -> New Project -> Android application project
- Application Name -> “Testing”
- Project Name -> “Testing_Robotium
- Next ...
- New -> Android Test ProjectProject Name -> “Testing”Next . Select “this project”
- Copy/ Take Apk to test
- Open as Archive
- Delete META-INF file
- Change the sign and install the Apk
- Copy ~/.android/debug.keystore to apk containing directory.
- jarsigner -verbose -keystore debug.keystore ApkUnderTest.apk androiddebugkey
- jarsigner -verify ApkUnderTEst.apk
- Create tmp Folder
- zipalign -v 4 ApkUnderTest.apk tmp\ApkUnderTest.apk
- adb install tmp/ApkUnderTest.apk
- Android Test project
- Build Path-> android Build path
- Android test Project
- Change Activity launch name
- Change Android Manifest .xml file \
- <instrumentationandroid:targetPackage="com.Example.ApplicationTesting"
with<instrumentationandroid:targetPackage="com.Example.ApplicationToTest"This you will get it from Logcat. - Make a class and Paste the code.
package
com.example.testing_robotium.test;
import
android.test.ActivityInstrumentationTestCase2;
import
android.view.View;
import
com.jayway.android.robotium.solo.Solo;
public class
Test_sensor_simple extends ActivityInstrumentationTestCase2 {
// this is the
name of the Activity u are launching i.e the main activity of the
android App
// u have to place
the name of the main activity of the application under test .
private static
final String LAUNCHER_ACTIVITY_FULL_CLASSNAME =
"com.invensense.app.sensorsimple.SensorSimpleActivity";
// this will check
if the Activity u have mentioned is present on the Device
private static
Class launcherActivityClass;
static {
try {
launcherActivityClass
= Class
.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
} catch
(ClassNotFoundException e) {
throw new
RuntimeException(e);
}
}
public
Test_sensor_simple() throws ClassNotFoundException {
super(launcherActivityClass);
}
//initialize the
Robot class
private Solo
solo;
// this is to
start the activity which need to be Tested
@Override
protected void
setUp() throws Exception {
solo = new
Solo(getInstrumentation(), getActivity());
}
public void
testDisplayBlackBox1() {
solo.sleep(3000);
solo.clickOnCheckBox(2);
solo.scrollToSide(Solo.RIGHT);
solo.clickOnText("Game",
3);
solo.sleep(1000);
solo.clickOnText("Normal");
solo.sleep(5000);
}
// this is the
test Cases
//this is to close
the Activity After the Test cases are completed
@Override
public void
tearDown() throws Exception {
solo.finishOpenedActivities();
}
}
No comments:
Post a Comment