Launching app and executing some test cases with Robotium

此生再无相见时 提交于 2020-01-25 11:34:28

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!