title: ActivityUnitTestCase and Google Maps Android API v2
body: <p>I have an Android project that uses external library project for Google Maps Android API v2 (<code>google-play-services_lib</code>).</p>
  
  <p>I also have testing project, which tests my project form first point.</p>
  
  <pre><code>package third.task.android.test;
  
  import third.task.android.CompassActivity;
  import third.task.android.R;
  import android.app.Activity;
  import android.content.Intent;
  import android.test.ActivityUnitTestCase;
  
  public class CompassActivityTest extends ActivityUnitTestCase&lt;CompassActivity&gt; {
  
      public CompassActivityTest() {
          super(CompassActivity.class);
      }
  
      public void testTruth() {
          assertTrue(true);
      }
  
      public void testPreConditions() {
          startActivity(new Intent(getInstrumentation().getTargetContext(), CompassActivity.class), null, null);
          Activity activity = getActivity();
          assertNull(activity.findViewById(R.id.compasRadar));
      }
  }
  </code></pre>
  
  <p>Here is my failure trace, which actually shows error about loading <code>class="com.google.android.gms.maps.MapFragment"</code></p>
  
  <pre><code>android.view.InflateException: Binary XML file line #8: Error inflating class fragment
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
  at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
  at android.app.Activity.setContentView(Activity.java:1924)
  at third.task.android.CompassActivity.onCreate(CompassActivity.java:55)
  at android.app.Activity.performCreate(Activity.java:5206)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
  at android.test.ActivityUnitTestCase.startActivity(ActivityUnitTestCase.java:158)
  at third.task.android.test.CompassActivityTest.testPreConditions(CompassActivityTest.java:19)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at android.test.InstrumentationTestCase.runMethod(InstrumentationTestCase.java:214)
  at android.test.InstrumentationTestCase.runTest(InstrumentationTestCase.java:199)
  at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:192)
  at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:177)
  at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:555)
  at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1608)
  Caused by: java.lang.IllegalStateException: Not on the main thread
  at maps.am.r.b(Unknown Source)
  at maps.ar.d.b(Unknown Source)
  at maps.y.ae.setCompassEnabled(Unknown Source)
  at maps.y.ae.a(Unknown Source)
  at maps.y.ae.a(Unknown Source)
  at maps.y.bu.a(Unknown Source)
  at maps.y.p.onCreateView(Unknown Source)
  at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
  at android.os.Binder.transact(Binder.java:326)
  at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
  at com.google.android.gms.maps.MapFragment$b.onCreateView(Unknown Source)
  at com.google.android.gms.internal.d$4.a(Unknown Source)
  at com.google.android.gms.internal.d.a(Unknown Source)
  at com.google.android.gms.internal.d.onCreateView(Unknown Source)
  at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:807)
  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1013)
  at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1112)
  at android.app.Activity.onCreateView(Activity.java:4857)
  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
  ... 24 more
  </code></pre>
  
  <p>When I remove code responsible for displaying map in layout and also map-dependent code snippets, everything works fine, but I have to test my application with full functionality including maps.
  Is there any way to do this?</p>