[android-developers] Re: Why there is an error when I doing unit test with ActivityInstrumentationTestCase2?

2009-08-25 Thread android.bu...@gmail.com
Hi Dianne, I have tried to annotate the test method with UiThreadTest, but still it doesn't work, the trace log is: java.lang.RuntimeException: This method can not be called from the main application thread at android.app.Instrumentation.validateNotAppThread (Instrumentation.java:1500) at

[android-developers] Re: Why there is an error when I doing unit test with ActivityInstrumentationTestCase2?

2009-08-25 Thread android.bu...@gmail.com
I have found the root cause of this problem. That's because of getInstrumentation().waitForIdleSync() I have seen someone else use waitForIdleSync() after UI action, I want to know if it is necessary, and in which case we need to call this method? If we want to call it, how do we call it

[android-developers] Re: Why there is an error when I doing unit test with ActivityInstrumentationTestCase2?

2009-08-25 Thread Dianne Hackborn
Annotations have nothing to do with this, waitForIdleSync() has nothing to do with this, it's just a basic aspect of Android that you can only call on to UI objects from the thread running the UI. Use this:

[android-developers] Re: Why there is an error when I doing unit test with ActivityInstrumentationTestCase2?

2009-08-25 Thread android.bu...@gmail.com
Hi Dianne, The following code can work well in my computer: @UiThreadTest public void testBikeButton(){ //click the bike button bike_btn.performClick(); .. //I delete the following code, then it works //getInstrumentation().waitForIdleSync();

[android-developers] Re: Why there is an error when I doing unit test with ActivityInstrumentationTestCase2?

2009-08-24 Thread android.bu...@gmail.com
no one know it? On Aug 24, 11:01 am, android.bu...@gmail.com android.bu...@gmail.com wrote: I am using ActivityInstrumentationTestCase2 to do some test for an activity. I get a button in the setUp() method like this: protected void setUp() throws Exception {         super.setUp();        

[android-developers] Re: Why there is an error when I doing unit test with ActivityInstrumentationTestCase2?

2009-08-24 Thread Dianne Hackborn
As the error says, you are calling peformClick() for a different thread than the UI thread (here the instrumentation thread). You can use the Instrumentation API to perform a call on the UI thread. On Mon, Aug 24, 2009 at 6:08 PM, android.bu...@gmail.com android.bu...@gmail.com wrote: no one