问题
I am new to Robotium and tried to execute following code to launch an app and perform some functions.
An example would be, launch messaging app on android emulator and send a text message "Hi" to a user "test".
package com.example.android.test;
import com.example.android.NewUserActivity;
import com.jayway.android.robotium.solo.Solo;
import android.test.ActivityInstrumentationTestCase2;
public class NewUserActivityTest extends ActivityInstrumentationTestCase2<NewUserActivity> {
private Solo solo;
public NewUserActivityTest() {
super("com.example.android", NewUserActivity.class);
}
public void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
@Override
public void tearDown() throws Exception {
try {
solo.finalize();
} catch (Throwable e) {
e.printStackTrace();
}
getActivity().finish();
super.tearDown();
}
public void sms() throws Exception{
assertTrue(solo.searchText("Messaging"));
solo.clickOnText("Messaging");
assertTrue(solo.searchText("New message"));
solo.clickOnButton("New message");
solo.enterText(0, "Test");
solo.enterText(1, "Hi");
}
}
With this code, Eclipse runs the test cases but I don't see it on emulator. I understand the package here is a dummy one, I want to know If I am doing it wrong?
回答1:
Test methods that you want to be executed must have the prefix "test", e.g. "testSms".
来源:https://stackoverflow.com/questions/7747660/launching-app-and-executing-some-test-cases-with-robotium