2011-09-19 22 views
-2

我一直在努力實現數據庫中robotium,這樣我可以參數化,使之面向數據的,但我完全失去了請指導me.My robotium代碼是下面提到請指導我我如何能打開數據庫與sqlite連接。參數化robotium

package com.dialog.test; 

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

public class TestNew extends ActivityInstrumentationTestCase2 { 
    private Solo solo; 


    //private Activity Main; 
    private static Class class1; 
    static 
    { 
     try { 
      class1=Class.forName("com.botskool.DialogBox.DialogBox"); 
     } catch (ClassNotFoundException e) { 
      e.printStackTrace(); 
     } 
    } 
    public TestNew() { 
     super("com.botskool.DialogBox", class1); 
    } 

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

    @Override 
    protected void tearDown() throws Exception{ 
     try { 
      this.solo.finalize(); 
      } catch (Throwable e) { 
       e.printStackTrace(); 
      } 
      getActivity().finish(); 
       super.tearDown(); 
      } 

    public void testDisplay(){ 
     solo.clickOnButton(0); 
     solo.clickOnButton("Ok"); 
     solo.clickOnButton(2); 
    } 
} 

即使是最小的指導,將有很大的幫助謝謝

+0

你面對什麼問題? – njzk2

+0

我無法連接它的SQLite數據庫,這樣我可以把它驅動的數據。我正在與機器人工作apk。 –

+0

您需要重新構建你的問題在一個更好的辦法! – TechSpellBound

回答

0

您可以使用Java文件IO在robotium腳本集成。提供文件路徑爲像/system/docs/test1.txt Android設備的路徑。您可以提供文件的細節和使用亞行推命令的文件推送到設備。當腳本運行時,您的參數將被訪問。我給你機器人測試用例的示例代碼:

public void test(){ 


    String strLine = "",PHN1="", MSG="", siters=""; 
    File f = null; 
    try { 

     f = new File("/system/SendSMS.txt"); 
     FileInputStream fileIS = new FileInputStream(f); 
     BufferedReader buf = new BufferedReader(new InputStreamReader(fileIS)); 
     String readString = new String(); 
     while ((readString = buf.readLine()) != null) { 
      strLine = strLine + readString; 
     } 

    } catch (Exception e) { 

     Log.e("ERROR", "" + e.getMessage()); 
     e.printStackTrace(); 
    } 
    PHN1 = strLine.substring(strLine.indexOf("[PHN1]")+"[PHN1]".length(), strLine.indexOf("[$PHN1]")); 
    MSG = strLine.substring(strLine.indexOf("[MSG]")+"[MSG]".length(), strLine.indexOf("[$MSG]")); 
    siters = strLine.substring(strLine.indexOf("[ITERS]")+"[ITERS]".length(), strLine.indexOf("[$ITERS]")); 
    int iters = Integer.valueOf(siters); 
    Log.i("D2Tech","SMS Contact : "+PHN1); 
    Log.i("D2Tech","SMS Message : "+MSG); 
    Log.i("D2Tech","SMS Iterations : "+iters); 
    PHN1="0183030689,0183030687"; 
    iters=50; 

    for(int j = 1; j<= iters ; j++){ 

      solo.clickOnText("New message"); 


      solo.enterText(0, PHN1); 

      solo.enterText(1, MSG + j); 
      solo.goBack(); 
      solo.clickOnButton("Send"); 
      solo.goBack(); 
      Log.i("D2Tech","SMS Message number : "+j); 

    } 
    solo.waitForDialogToClose(1000); 
} 
+1

上面的代碼是用於發送多個SMS到另一個設備 – Killy

+0

我只是想它會讓你在很短的,而知道:) –