1

我正在使用 Robotium 来测试 android 应用程序。

下面是我的一段代码。我也想验证数据库详细信息。如何添加数据库连接并验证这一点?

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, "robot2@gmail.com");
        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();
    }*/
}
4

1 回答 1

1

您可以为此使用 Java API,首先建立与数据库的连接:

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

然后使用executeQuery()方法创建查询。

于 2012-11-22T20:24:58.027 回答