在Android中运行unit testing时,Intent解析为不同的进程

我有一个使用两个活动的小应用程序。 这两个活动都inheritance自MapActivity并显示地图(com.google.android.maps)。

自Android谷歌地图文档说

每个进程只支持一个MapActivity。 同时运行的多个MapActivities可能会以意外和不希望的方式干扰。

我修改了我的清单,在两个不同的进程中运行这两个活动(我删除了一些行以使其缩短):

           Unit           

现在应用程序运行正常,但是当我在两个活动上运行unit testing时,我遇到了问题。 例如:

 package com.example.myapp; public class Activity1Test extends ActivityInstrumentationTestCase2 { Activity1 mActivity; public Activity1Test() { super("com.example.myapp.Activity1", Activity1.class); } @Override protected void setUp() throws Exception { super.setUp(); setActivityInitialTouchMode(false); setActivityIntent(new Intent()); mActivity = getActivity(); //An exception is thrown at this line } } 

当我调用getActivity()方法时抛出exception:

 java.lang.RuntimeException: Intent in process com.example.myapp resolved to different process .Activity1: Intent { flg=0x10000000 cmp=com.example.myapp/.Activity1 } at android.app.Instrumentation.startActivitySync(Instrumentation.java:377) at android.test.InstrumentationTestCase.launchActivityWithIntent(InstrumentationTestCase.java:119) at android.test.ActivityInstrumentationTestCase2.getActivity(ActivityInstrumentationTestCase2.java:100) at com.example.myapp.Activity1Test.setUp(Activity1Test.java:28) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:169) at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:154) at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:520) at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1447) 

有没有办法让unit testing“解决”正确的过程?

Instrumentation在同一进程中运行所有应用程序组件。

在此处输入图像描述