2012-11-09 68 views
1

我正在使用Robotium來測試android應用程序。如何使用robotium連接數據庫?

下面是我的一段代碼。我想驗證數據庫的細節。如何添加數據庫連接並驗證這一點?

package com.robotiumtest.android; 

import android.test.ActivityInstrumentationTestCase2; 

import com.jayway.android.robotium.solo.Solo; 

@SuppressWarnings("unchecked") 
public class Home extends ActivityInstrumentationTestCase2 { 

    private static final String TARGET_PACKAGE_ID = "com.robotiumtest.android"; 
    private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "xxxxx"; 
    private static Class<?> launcherActivityClass; 
    static { 
     try { 
      launcherActivityClass = Class 
        .forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME); 
     } catch (ClassNotFoundException e) { 
      throw new RuntimeException(e); 
     } 
    } 

    @SuppressWarnings("unchecked") 
    public Home() throws ClassNotFoundException { 
     super(TARGET_PACKAGE_ID, launcherActivityClass); 
    } 

    private Solo solo; 

    @Override 
    protected void setUp() throws Exception { 
     solo = new Solo(getInstrumentation(), getActivity()); 
    } 

    public void testCanOpenSettings() { 
     // Press the Menu 
     solo.pressMenuItem(0); 
      int i = 0; 
     //solo.clickOnButton(3); 
     //solo.wait(10); 
     //solo.clickOnButton(0); 
     //solo.waitForText("Title"); 
     //solo.clickOnText("Title"); 
     solo.enterText(0,"xxxxx"); 
     solo.clickOnButton(0); 
     solo.waitForText("xxx"); 
     solo.clickOnButton("xx"); 
     solo.waitForText("xxxx"); 
     solo.enterText(0, "[email protected]"); 
     solo.enterText(1, "asdfghjkl"); 
     solo.clickOnButton(1);   
     solo.sleep(10000); 
     solo.waitForText("school"); 
     solo.enterText(0, "vsb"); 
     solo.clickOnButton(0); 
     solo.waitForText("xxxxxx"); 
     solo.clickOnText("1"); 
     solo.clickOnText("2"); 
     solo.enterText(0, "672"); 
     solo.searchButton("BUY"); 
     solo.clickOnButton("BUY"); 
     solo.waitForText("Please confirm"); 
     solo.clickOnButton(1); 
     /*solo.sleep(10000);*/ 
     solo.waitForText("Thank you"); 
     solo.sleep(10000); 
     solo.clickOnButton(1); 
     if (solo.searchText("No thanks")) 
     { 
      solo.clickOnText("No thanks"); 
     } 
     solo.waitForText("Welcome"); 
     solo.clickOnButton("LOGOUT"); 
     solo.sleep(10000); 
     } 
/* 
    @Override 
    public void tearDown() throws Exception { 
     try { 
      solo.finalize(); 
     } catch (Throwable e) { 
      e.printStackTrace(); 
     } 
     getActivity().finish(); 
     super.tearDown(); 
    }*/ 
} 
+0

我正在使用robotium自動化腳本註冊應用程序,一旦腳本運行,我想驗證它正在添加的數據庫的詳細信息是否正確或不使用robotium?如何驗證這一點? – ChanGan

回答

1

您可以使用Java API來此,先建立連接與數據庫:

Class.forName("com.mysql.jdbc.Driver"); 
connection = DriverManager.getConnection(URL, USERNAME, PASSWORD); 
Statement st=con.createStatement(); 

和未來使用executeQuery()方法來創建查詢。