google-play-services_lib
我有一个使用 Google Maps Android API v2 ( )的外部库项目的 Android 项目。
我也有测试项目,它首先测试我的项目形式。
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<CompassActivity> {
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));
}
}
这是我的失败跟踪,实际上显示了有关加载的错误class="com.google.android.gms.maps.MapFragment"
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
当我删除负责在布局中显示地图的代码以及与地图相关的代码片段时,一切正常,但我必须使用包括地图在内的全部功能测试我的应用程序。有没有办法做到这一点?