I wrote a simplest test based on
android.test.ActivityInstrumentationTestCase2.

[sourcecode language="java"]
package andtest.threads.asynctask;

import java.util.concurrent.ExecutionException;

import andtest.R;
import andtest.threads.asynctask.AsyncTaskDemo;
import andtest.threads.asynctask.AsyncTaskDemoActivity;
import android.test.ActivityInstrumentationTestCase2;
import android.test.UiThreadTest;
import android.widget.Button;


public class AsyncTaskDemoTest3 extends
ActivityInstrumentationTestCase2<AsyncTaskDemoActivity> {

        public AsyncTaskDemoTest3() {
                super("andtest.threads.asynctask", AsyncTaskDemoActivity.class);
        }


        protected void setUp() throws Exception {
                super.setUp();
        }

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

        @UiThreadTest
        public final void testExecute() {

        Button btnStart = (Button)
getActivity().findViewById(R.id.Button01);
                assertNotNull(btnStart);
        btnStart.performClick();
        }

}
[/sourcecode]

Whenever I try to run it I got:
-----------------
java.lang.RuntimeException: This method can not be called from the
main application thread
at
android.app.Instrumentation.validateNotAppThread(Instrumentation.java:
1500)
at android.app.Instrumentation.startActivitySync(Instrumentation.java:
439)
at
android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:
106)
at
android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:
84)
at
android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:
87)
at
andtest.threads.asynctask.AsyncTaskDemoTest3.testExecute(AsyncTaskDemoTest3.java:
36)
. . .

Based on error message I thought that possible a problem in calling
'getActivity()' from main UI thread (ridiculous), so I removed
annotation line
        @UiThreadTest

Now I got the error:
----------------
java.lang.RuntimeException: Unable to resolve activity for: Intent
{ action=android.intent.action.MAIN flags=0x10000000
comp={andtest.threads.asynctask/
andtest.threads.asynctask.AsyncTaskDemoActivity} }
at android.app.Instrumentation.startActivitySync(Instrumentation.java:
447)
at
android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:
106)
at
android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase.java:
84)
at
android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:
87)
at
andtest.threads.asynctask.AsyncTaskDemoTest3.testExecute(AsyncTaskDemoTest3.java:
36)
. . .


Any ideas?

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to