0

anyone can help me.I want to my testcases sleep to wait the textview text change ,but it seems the Thread.sleep() can not work !

backgroud : I use ActivityUnitTestCase to test one of my activity . below is the testcase, from log I can not get the changed text .

public void testCanStartup() throws Exception{
    m_activty = startActivity(m_intent, null, null);
    assertNotNull(m_activty);

                //get textview to check the view text's changes when oncreate and onresume
    TextView mem_percentview= (TextView) m_activty.findViewById(cn.opda.a.phonoalbumshoushou.R.id.mem_percent);

    Thread.sleep(50000);
    getInstrumentation().callActivityOnResume(m_activty);
    Log.v(DEBUGTAG,"mem text result is : " + mem_percentview.getText().toString());
    TextView actual_mempercentview = (TextView) m_activty.findViewById(cn.opda.a.phonoalbumshoushou.R.id.mem_percent);
    assertEquals(mem_percentview.getText().toString(),actual_mempercentview.getText().toString() );

}

1 Answers1

0

How about:

  mem_percentview.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
            Log.v(DEBUGTAG,"mem text result is : " + charSequence;
        }

        @Override
        public void afterTextChanged(Editable editable) {
        }
    });
S.D.
  • 29,290
  • 3
  • 79
  • 130
  • thanks for your suggestion, it seems can not work ,I guess maybe the problem of mutiple thread in my test target application. since this Activity will start an receiver to calculate the system memory information. it will send back data to the Activity thread. I still can not get nothing from your code :( – user1624097 Aug 25 '12 at 06:51