类android.test.ActivityUnitTestCase源码实例Demo

下面列出了怎么用android.test.ActivityUnitTestCase的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: aedict   文件: AndroidTester.java
/**
 * Start the activity under test, in the same way as if it was started by
 * ActivityUnitTestCase.startActivity, providing the arguments it supplied.
 * When you use this method to start the activity, it will automatically be
 * stopped by tearDown().
 * <p/>
 * This method will call onCreate(), if you wish to further exercise
 * Activity life cycle methods, set the fullStart parameter to true.
 * <p/>
 * Do not call from your setUp() method. You must call this method from each
 * of your test methods.
 * 
 * @param intent
 *            The Intent as if supplied to startActivity(Intent).
 * @param savedInstanceState
 *            The instance state, if you are simulating this part of the
 *            life cycle. Typically null.
 * @param lastNonConfigurationInstance
 *            This Object will be available to the Activity if it calls
 *            getLastNonConfigurationInstance(). Typically null.
 * @param fullStart
 *            if true then the full activity start-up is performed:
 *            onCreate(), onStart(), onResume(). If false then only the
 *            onCreate() method is invoked.
 * @return the activity instance.
 */
public T startActivity(final Intent intent, Bundle savedInstanceState, final Object lastNonConfigurationInstance, final boolean fullStart) {
	try {
		final Method m = ActivityUnitTestCase.class.getDeclaredMethod("startActivity", Intent.class, Bundle.class, Object.class);
		m.setAccessible(true);
		final T result = activityClass.cast(m.invoke(test, intent, savedInstanceState, lastNonConfigurationInstance));
		if (fullStart) {
			test.getInstrumentation().callActivityOnStart(test.getActivity());
			test.getInstrumentation().callActivityOnResume(test.getActivity());
		}
		return result;
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
源代码2 项目: aedict   文件: AndroidTester.java
/**
 * Creates new tester instance.
 * 
 * @param test
 *            the JUnit test class instance.
 * @param activityClass
 *            the activity under test.
 */
public AndroidTester(final ActivityUnitTestCase<T> test, final Class<T> activityClass) {
	this.test = test;
	this.activityClass = activityClass;
}