robotium test package build failed

时间:2016-08-19 04:50:57

标签: android robotium

i have generated test cases using automated testing tool for an android app then i used the ant debug install test command to test the app but the test package failed to build with two errors. The errors are below.

.../src/aarddict/android/DictionariesActivityTest.java:4635: error: variable INDEX is already defined in method testPath207() [javac] int INDEX = 0; // MAKE SURE IT INDEXES THE CORRECT TEXT EDIT

.../src/aarddict/android/DictionariesActivityTest.java:5162: error: variable INDEX is already defined in method testPath231() [javac] int INDEX = 0; // MAKE SURE IT INDEXES THE CORRECT TEXT EDIT

Here is the part of the test cases, the lines causing the errors,

package aarddict.android.tests;

import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;
import com.robotium.solo.Solo;
import android.view.KeyEvent;
import android.widget.TextView;
import aarddict.android.R;
import android.content.res.Configuration;
import android.view.View;
import android.app.Activity;
import android.view.ViewGroup;
import java.util.ArrayList;
import aarddict.android.LookupActivity;

public class DictionariesActivityTest extends ActivityInstrumentationTestCase2<LookupActivity> {

  private Solo solo;
  private final static String TAG = "Gator.TestGenClient";


  public DictionariesActivityTest() {
    super(LookupActivity.class);
  }

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

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


  public void testPath001() throws Exception {
    // Launcher node ===> ACT[aarddict.android.ArticleViewActivity]685
    // LAUNCHER_NODE[]4862 => ACT[aarddict.android.LookupActivity]649
    // Event: implicit_launch_event, on: LAUNCHER_NODE[]4862, with id: R.id.null (0xffffffff), with title: null
    // with handlers: []
    // Implicit Launch. BenchmarkName: aarddict
    assertActivity(aarddict.android.LookupActivity.class);
    // ACT[aarddict.android.LookupActivity]649 => ACT[aarddict.android.ArticleViewActivity]685
    // Event: item_click, on: INFL[android.widget.ListView,WID[2131099662|einkLookupResult]400,4478]4481, with id: R.id.einkLookupResult (0x7f06000e), with title: null
    // with handlers: [<aarddict.android.LookupActivity$WordAdapter: void onItemClick(android.widget.AdapterView,android.view.View,int,long)>]
    // TODO
    int ITEM_INDEX_1000 = 1; // MAKE SURE IT INDEXES THE ITEM EXPECTED
    int LIST_INDEX_1001 = 0; // MAKE SURE IT INDEXES THE LIST EXPECTED
    solo.clickInList(ITEM_INDEX_1000, LIST_INDEX_1001);
    assertActivity(aarddict.android.ArticleViewActivity.class);
    // ACT[aarddict.android.ArticleViewActivity]685 => ACT[aarddict.android.ArticleViewActivity]685
    // Event: click, on: INFL[android.widget.Button,WID[2131099652|NextButton]388,4313]4315, with id: R.id.NextButton (0x7f060004), with title: null
    // with handlers: [<aarddict.android.ArticleViewActivity$5: void onClick(android.view.View)>]
    final View v_1002 = solo.getView(R.id.NextButton);
    assertTrue("Button: Not Enabled", v_1002.isEnabled());
    solo.clickOnView(v_1002); 
    assertActivity(aarddict.android.ArticleViewActivity.class);
  }

 public void testPath207() throws Exception {
    // Launcher node ===> ACT[aarddict.android.LookupActivity]649
    // LAUNCHER_NODE[]4862 => ACT[aarddict.android.LookupActivity]649
    // Event: implicit_launch_event, on: LAUNCHER_NODE[]4862, with id: R.id.null (0xffffffff), with title: null
    // with handlers: []
    // Implicit Launch. BenchmarkName: aarddict
    assertActivity(aarddict.android.LookupActivity.class);
    // ACT[aarddict.android.LookupActivity]649 => ACT[aarddict.android.LookupActivity]649
    // Event: enter_text, on: INFL[android.widget.EditText,WID[2131099659|wordInput]410,4368]4371, with id: R.id.wordInput (0x7f06000b), with title: null
    // with handlers: [<aarddict.android.LookupActivity$5: void beforeTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void onTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void afterTextChanged(android.text.Editable)>]
    // TODO
    int INDEX = 0; // MAKE SURE IT INDEXES THE CORRECT TEXT EDIT
    solo.enterText(INDEX, "some text");
    assertActivity(aarddict.android.LookupActivity.class);
    // ACT[aarddict.android.LookupActivity]649 => ACT[aarddict.android.LookupActivity]649
    // Event: enter_text, on: INFL[android.widget.EditText,WID[2131099659|wordInput]410,4479]4482, with id: R.id.wordInput (0x7f06000b), with title: null
    // with handlers: [<aarddict.android.LookupActivity$5: void beforeTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void onTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void afterTextChanged(android.text.Editable)>]
    // TODO
    int INDEX = 0; // MAKE SURE IT INDEXES THE CORRECT TEXT EDIT
    solo.enterText(INDEX, "some text");
    assertActivity(aarddict.android.LookupActivity.class);
  }

.....

public void testPath231() throws Exception {
    // Launcher node ===> ACT[aarddict.android.LookupActivity]649
    // LAUNCHER_NODE[]4862 => ACT[aarddict.android.LookupActivity]649
    // Event: implicit_launch_event, on: LAUNCHER_NODE[]4862, with id: R.id.null (0xffffffff), with title: null
    // with handlers: []
    // Implicit Launch. BenchmarkName: aarddict
    assertActivity(aarddict.android.LookupActivity.class);
    // ACT[aarddict.android.LookupActivity]649 => ACT[aarddict.android.LookupActivity]649
    // Event: enter_text, on: INFL[android.widget.EditText,WID[2131099659|wordInput]410,4479]4482, with id: R.id.wordInput (0x7f06000b), with title: null
    // with handlers: [<aarddict.android.LookupActivity$5: void beforeTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void onTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void afterTextChanged(android.text.Editable)>]
    // TODO
    int INDEX = 0; // MAKE SURE IT INDEXES THE CORRECT TEXT EDIT
    solo.enterText(INDEX, "some text");
    assertActivity(aarddict.android.LookupActivity.class);
    // ACT[aarddict.android.LookupActivity]649 => ACT[aarddict.android.LookupActivity]649
    // Event: enter_text, on: INFL[android.widget.EditText,WID[2131099659|wordInput]410,4368]4371, with id: R.id.wordInput (0x7f06000b), with title: null
    // with handlers: [<aarddict.android.LookupActivity$5: void beforeTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void onTextChanged(java.lang.CharSequence,int,int,int)>, <aarddict.android.LookupActivity$5: void afterTextChanged(android.text.Editable)>]
    // TODO
    int INDEX = 0; // MAKE SURE IT INDEXES THE CORRECT TEXT EDIT
    solo.enterText(INDEX, "some text");
    assertActivity(aarddict.android.LookupActivity.class);
  }

Please, can someone help me to fix this...

1 个答案:

答案 0 :(得分:0)

您的错误日志会在函数testPath207()testPath231()中告诉您“已定义变量INDEX”,因为您有一行

int INDEX = 0; 

两次。如果要在同一函数中为变量分配另一个值,则不需要前面的int