0

任何人都可以帮助我。我想让我的测试用例休眠以等待 textview 文本更改,但似乎 Thread.sleep() 无法正常工作!

背景:我使用 ActivityUnitTestCase 来测试我的一项活动。下面是测试用例,从日志中我无法获得更改后的文本。

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() );

}
4

1 回答 1

0

怎么样:

  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) {
        }
    });
于 2012-08-25T05:54:06.020 回答