2

我使用 AndEngine 编写了一个游戏,我想使用 Robotium 进行测试。问题是robotium的拖动功能不起作用。我将robotum 4.0 jar 添加到构建路径并导出,我的清单文件似乎是正确的。第二个测试(操纵杆)失败,因为运动永远不会发生。这是测试类:

package cs428.uiuc.robotswarms.test;

    import junit.framework.Assert;

    import org.andengine.entity.sprite.AnimatedSprite;


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


    import cs428.uiuc.robotswarms.RobotSwarms;

    import android.test.ActivityInstrumentationTestCase2;


    public class testMotion extends ActivityInstrumentationTestCase2<RobotSwarms> {

public testMotion() {
    super(RobotSwarms.class);
}

private Solo solo;

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

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

private void waitForSpriteInitialisation(RobotSwarms ActivityData) {
    while (ActivityData.getPlayerSprite() == null) {

    }
}

public void testJoystickMovement() {
    RobotSwarms ActivityData = getActivity();
    final float fromX = 400.0f;
    float toX = 380.0f;
    final float fromY = 208.0f;
    float toY = 208.0f;
    AnimatedSprite playerSprite;
    waitForSpriteInitialisation(ActivityData);
    playerSprite = ActivityData.getPlayerSprite();
    float initialPlayerXPosition = playerSprite.getX();
    solo.sleep(2000);
    solo.drag(fromX, toX, fromY, toY, 5);
    solo.sleep(2000);

    playerSprite = ActivityData.getPlayerSprite();

    float playerMovedX = playerSprite.getX();
    Assert.assertTrue(playerMovedX != initialPlayerXPosition);

}


}

目标应用程序清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cs428.uiuc.robotswarms"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" android:debuggable="true">
    <activity
        android:name="cs428.uiuc.robotswarms.RobotSwarms"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

测试项目清单文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="cs428.uiuc.robotswarms.test"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="8" />

<instrumentation
    android:name="android.test.InstrumentationTestRunner"
    android:targetPackage="cs428.uiuc.robotswarms" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >
    <uses-library android:name="android.test.runner" />
</application>

我曾尝试使用 TouchUtils 而不是 Robotium,但这似乎也不起作用。编辑:撞

4

0 回答 0