android.test.ActivityUnitTestCase Java Examples

The following examples show how to use android.test.ActivityUnitTestCase. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AndroidTester.java    From aedict with GNU General Public License v3.0 3 votes vote down vote up
/**
 * 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);
	}
}
 
Example #2
Source File: AndroidTester.java    From aedict with GNU General Public License v3.0 2 votes vote down vote up
/**
 * 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;
}