我正在尝试使用robotium运行Android JUnit3测试:
import android.test.ActivityInstrumentationTestCase2;
import com.package.sample.MyActivityClass;
import com.jayway.android.robotium.solo.Solo;
public class TestSample extends ActivityInstrumentationTestCase2<MyActivityClass> {
private Solo solo;
public TestSample() {
super("com.package.sample", MyActivityClass.class);
}
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
public void clickbutton1() throws Exception{
solo.clickOnButton("abc");
solo.setActivityOrientation(Solo.LANDSCAPE);
assertTrue(solo.searchText("load"));
}
@Override
protected void tearDown() throws Exception{
solo.finishOpenedActivities();
}
}
JUnit探索显示0/0测试运行。调试器没有点击这里提到的任何代码路径,Console输出“test run finished”??:
Uploading MyAppTest.apk onto device 'emulator-5554'
Installing MyAppTest.apk...
Success!
Project dependency found, installing: MyApp
Uploading MyApp.apk onto device 'emulator-5554'
Installing MyApp.apk...
Success!
Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554
Collecting test information
Sending test information to Eclipse
Running tests...
Test run finished
有没有人知道出了什么问题?我虔诚地遵循了机器人教程中的所有步骤。我知道围绕这个有很多问题,但我已经处理了所有答案。
此外,Robotium与JUnit4 here有类似的问题。
答案 0 :(得分:3)
是的,我知道出了什么问题。
要运行测试,您需要使用test
开始测试。所以你的代码应该是这样的:
import android.test.ActivityInstrumentationTestCase2;
import com.package.sample.MyActivityClass;
import com.jayway.android.robotium.solo.Solo;
public class TestSample extends ActivityInstrumentationTestCase2<MyActivityClass> {
private Solo solo;
public TestSample() {
super("com.package.sample", MyActivityClass.class);
}
protected void setUp() throws Exception {
super.setUp();
solo = new Solo(getInstrumentation(), getActivity());
}
//the test methods MUST begin with test...
public void testClickbutton1() throws Exception{
solo.clickOnButton("abc");
solo.setActivityOrientation(Solo.LANDSCAPE);
assertTrue(solo.searchText("load"));
}
@Override
protected void tearDown() throws Exception{
solo.finishOpenedActivities();
}
}
前一段时间我遇到过类似的问题,Robotium没有最好的文档。我希望这可以帮助你:))
答案 1 :(得分:1)
我做了你所说的一切,但我仍然得到0/0 test的错误。我找到了解决方案,这与构造函数有关:
// I DELETED THIS CONSTRUCTOR
public TestHomeScreenTest(String pkg, Class<ScreenSlidePagerActivity> activityClass) {
super(pkg, activityClass);
}
//GOOD SOLUTION:
public TestHomeScreenTest() {
super("com.dolphin.homescreen", ScreenSlidePagerActivity.class);
}
现在它就是WOOORKS! :)