Hi Vladimir,

Maybe this example will help:
http://mihaifonoage.blogspot.com/2010/01/unit-and-functional-testing-in-android.html

On Feb 24, 10:00 am, vladimir kroz <vladimir.k...@gmail.com> wrote:
> 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(Instrumentati 
> onTestCase.java:
> 106)
> at
> android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase 
> .java:
> 84)
> at
> android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumen 
> tationTestCase2.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(Instrumentati 
> onTestCase.java:
> 106)
> at
> android.test.InstrumentationTestCase.launchActivity(InstrumentationTestCase 
> .java:
> 84)
> at
> android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumen 
> tationTestCase2.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 android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to