From bc7f4f0e1275fca1484c02ba465fce907c6692f7 Mon Sep 17 00:00:00 2001 From: Filip Gruszczynski Date: Mon, 29 Sep 2014 14:05:19 -0700 Subject: Log exception when creating Activity in ActivityUnitTestCase. If the creation of an Activity fails, it is impossible to determine what went wrong. We should log the exception immediately before failing on assert. Change-Id: Ie6cbe87ff342b8d60989f5e1a6ffa3efc058c585 --- test-runner/src/android/test/ActivityUnitTestCase.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'test-runner/src') diff --git a/test-runner/src/android/test/ActivityUnitTestCase.java b/test-runner/src/android/test/ActivityUnitTestCase.java index 8aa8824..40cca90 100644 --- a/test-runner/src/android/test/ActivityUnitTestCase.java +++ b/test-runner/src/android/test/ActivityUnitTestCase.java @@ -26,6 +26,9 @@ import android.os.Bundle; import android.os.IBinder; import android.test.mock.MockApplication; import android.view.Window; +import android.util.Log; + + /** * This class provides isolated testing of a single activity. The activity under test will @@ -73,6 +76,7 @@ import android.view.Window; public abstract class ActivityUnitTestCase extends ActivityTestCase { + private static final String TAG = "ActivityUnitTestCase"; private Class mActivityClass; private Context mActivityContext; @@ -132,27 +136,28 @@ public abstract class ActivityUnitTestCase if (mApplication == null) { setApplication(new MockApplication()); } - ComponentName cn = new ComponentName(mActivityClass.getPackage().getName(), + ComponentName cn = new ComponentName(mActivityClass.getPackage().getName(), mActivityClass.getName()); intent.setComponent(cn); ActivityInfo info = new ActivityInfo(); CharSequence title = mActivityClass.getName(); mMockParent = new MockParent(); String id = null; - + newActivity = (T) getInstrumentation().newActivity(mActivityClass, mActivityContext, token, mApplication, intent, info, title, mMockParent, id, lastNonConfigurationInstance); } catch (Exception e) { + Log.w(TAG, "Catching exception", e); assertNotNull(newActivity); } - + assertNotNull(newActivity); setActivity(newActivity); mAttached = true; } - + T result = getActivity(); if (result != null) { getInstrumentation().callActivityOnCreate(getActivity(), savedInstanceState); -- cgit v1.1