2012-09-20 61 views
0

我爲我的應用程序構建了一個Robotium測試用例。除了我需要手動與我的應用程序進行交互以使測試開始運行之外,一切都很好。這意味着我需要去應用程序中的另一個活動,然後測試案例將開始。 由於某種原因,我的測試不會在啓動時啓動。爲什麼我的robotium測試用例在啓動活動後沒有立即啓動?

public class TestApk extends ActivityInstrumentationTestCase2{ 
private static final String TARGET_PACKAGE_ID= "com.bizzabo.client"; 
private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.bizzabo.client.ui.activities.BzLauncher"; 
private static Class launcherActivityClass; 
static{ 
    try 
    { 
     launcherActivityClass=Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME); 
    } catch (ClassNotFoundException e){ 
     throw new RuntimeException(e); 
    }} 
public TestApk()throws ClassNotFoundException{ 
    super(launcherActivityClass); 
} 
private Solo solo; 
@Override 
protected void setUp() throws Exception 
{ 
    solo = new Solo(getInstrumentation(),getActivity()); 

} 

public void testInformationMenu() { 
    final int INFORMATION_VIEW_NO = 11; 

    solo.getCurrentActivity(); 
    solo.sleep(1000); 
    solo.goBack(); 
    solo.sleep(1000); 
    ArrayList<View> viewList = solo.getCurrentViews(); 
    solo.clickOnView(viewList.get(INFORMATION_VIEW_NO)); 
    solo.sleep(1000); 
    solo.clickOnText("Add Event"); 
    solo.sleep(1000); 
    solo.goBack(); 
    solo.clickOnView(viewList.get(INFORMATION_VIEW_NO)); 
    solo.clickOnText("Invite Your Friends"); 
    solo.sleep(1000); 
    solo.goBack(); 
    solo.clickOnView(viewList.get(10)); 
    solo.sleep(1000); 
    solo.enterText(0, "testbot"); 
    solo.sendKey(Solo.ENTER); 
    solo.sleep(5000); 
    solo.clickOnImage(2); 
    solo.sleep(1000); 
    solo.clickOnText("Join"); 
    solo.goBack(); 
    solo.clickOnText("Community"); 
    solo.sleep(1000); 
    solo.clickOnText("Join"); 
    solo.goBack(); 
    solo.clickOnText("HERE NOW"); 
    solo.sleep(1000); 
    solo.clickOnText("Check-In"); 
    solo.sleep(1000); 
    solo.goBack(); 
    solo.clickOnText("Opportunities"); 
    solo.clickOnText("Messages"); 
    solo.clickOnText("Offers"); 
    solo.sleep(1000); 
    solo.clickOnText("Event"); 
    solo.goBack(); 
    solo.sleep(1000); 
    solo.clickOnText("Information"); 
    solo.clickOnText("Join"); 
    solo.goBack(); 
    solo.clickOnText("+ Invite"); 
    solo.goBack(); 
    solo.clickOnText("Buzz"); 
    solo.goBack(); 
    solo.goBack(); 
    solo.drag(400, 400, 400, 300, 1); 
    solo.sleep(1000); 
} 

public void tearDown() throws Exception { 
    solo.finishOpenedActivities(); 
} 

}

回答

2

我相信這應該是簡單的打電話給你超:

public void setUp() throws Exception { 
    super.setUp(); 
    solo = new Solo(getInstrumentation(),getActivity()); 
} 

public void tearDown() throws Exception { 
    solo.finishOpenedActivities(); 
    super.tearDown(); 
} 

這應該幫助建立的一切,你的測試運行當然,假設你的類名是正確的!

0

在這行你寫活動從測試開始:你需要開始爲

LAUNCHER_ACTIVITY_FULL_CLASSNAME="com.bizzabo.client.ui.activities.BzLauncher"; 

檢查正常活動。

0

我在我的應用程序中有同樣的問題。在我的活動中,我有一個顯示GIF動畫的自定義視圖(webview)。如果我從Activity中刪除這個視圖,測試會在啓動時開始。但是如果這種觀點存在,那麼測試不會繼續,直到我手動切換到下一個活動。

相關問題