A - The container activity for the fragment under testF - The fragment under testpublic class FragmentTestRule<A extends FragmentActivity,F extends Fragment>
extends <any>
Idea extracted from: http://stackoverflow.com/a/38393087/842697
| Constructor and Description |
|---|
FragmentTestRule(java.lang.Class<A> activityClass,
java.lang.Class<F> fragmentClass)
Similar to
FragmentTestRule(Class, Class, boolean) but with "touch mode" disabled. |
FragmentTestRule(java.lang.Class<A> activityClass,
java.lang.Class<F> fragmentClass,
boolean initialTouchMode)
Similar to
FragmentTestRule(Class, Class, boolean, boolean) but defaults to launch
the activity under test once per
Test method. |
FragmentTestRule(java.lang.Class<A> activityClass,
java.lang.Class<F> fragmentClass,
boolean initialTouchMode,
boolean launchActivity)
Similar to
FragmentTestRule(Class, Class, boolean, boolean, boolean) but defaults to
launch the fragment under test once per
Test method. |
FragmentTestRule(java.lang.Class<A> activityClass,
java.lang.Class<F> fragmentClass,
boolean initialTouchMode,
boolean launchActivity,
boolean launchFragment)
Creates an
FragmentTestRule for the Fragment under test. |
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterActivityLaunched() |
static <F extends Fragment> |
create(java.lang.Class<F> fragmentClass)
Creates an
FragmentTestRule for the Fragment under test. |
static <F extends Fragment> |
create(java.lang.Class<F> fragmentClass,
boolean initialTouchMode)
Creates an
FragmentTestRule for the Fragment under test. |
static <F extends Fragment> |
create(java.lang.Class<F> fragmentClass,
boolean initialTouchMode,
boolean launchFragment)
Creates an
FragmentTestRule for the Fragment under test. |
protected F |
createFragment()
Override this method to set up the desired Fragment.
|
F |
getFragment() |
void |
launchFragment(F fragment)
Launches the Fragment under test.
|
public FragmentTestRule(java.lang.Class<A> activityClass, java.lang.Class<F> fragmentClass)
FragmentTestRule(Class, Class, boolean) but with "touch mode" disabled.activityClass - The container activity for the fragment under test. This must be a class
in the instrumentation targetPackage specified in the
AndroidManifest.xmlfragmentClass - The fragment under testFragmentTestRule(Class, Class, boolean)public FragmentTestRule(java.lang.Class<A> activityClass, java.lang.Class<F> fragmentClass, boolean initialTouchMode)
FragmentTestRule(Class, Class, boolean, boolean) but defaults to launch
the activity under test once per
Test method.
It is launched before the first
Before
method, and terminated after the last
After
method.activityClass - The container activity for the fragment under test. This must be a
class in the instrumentation targetPackage specified in the
AndroidManifest.xmlfragmentClass - The fragment under testinitialTouchMode - true if the Activity should be placed into "touch mode" when startedFragmentTestRule(Class, Class, boolean, boolean)public FragmentTestRule(java.lang.Class<A> activityClass, java.lang.Class<F> fragmentClass, boolean initialTouchMode, boolean launchActivity)
FragmentTestRule(Class, Class, boolean, boolean, boolean) but defaults to
launch the fragment under test once per
Test method.
It is launched before the first
Before
method, and terminated after the last
After
method.activityClass - The container activity for the fragment under test. This must be a
class in the instrumentation targetPackage specified in the
AndroidManifest.xmlfragmentClass - The fragment under testinitialTouchMode - true if the Activity should be placed into "touch mode" when startedlaunchActivity - true if the Activity should be launched once per
Test method. It will be launched before the first
Before method, and terminated after the last
After method.FragmentTestRule(Class, Class, boolean, boolean, boolean)public FragmentTestRule(java.lang.Class<A> activityClass, java.lang.Class<F> fragmentClass, boolean initialTouchMode, boolean launchActivity, boolean launchFragment)
FragmentTestRule for the Fragment under test.activityClass - The container activity for the fragment under test. This must be a
class in the instrumentation targetPackage specified in the
AndroidManifest.xmlfragmentClass - The fragment under testinitialTouchMode - true if the Activity should be placed into "touch mode" when startedlaunchActivity - true if the Activity should be launched once per
Test method. It will be launched before the first
Before method, and terminated after the last
After method.launchFragment - true if the Fragment should be launched once per
Test method. It will be launched before the first
Before method, and terminated after the last
After method.public static <F extends Fragment> FragmentTestRule<?,F> create(java.lang.Class<F> fragmentClass)
FragmentTestRule for the Fragment under test.
This factory uses a standard Activity to launch the fragment. If you need a special Activity use the constructors.
fragmentClass - The fragment under testFragmentTestRule(Class, Class)public static <F extends Fragment> FragmentTestRule<?,F> create(java.lang.Class<F> fragmentClass, boolean initialTouchMode)
FragmentTestRule for the Fragment under test.
This factory uses a standard Activity to launch the fragment. If you need a special Activity use the constructors.
fragmentClass - The fragment under testinitialTouchMode - true if the Activity should be placed into "touch mode" when startedFragmentTestRule(Class, Class, boolean)public static <F extends Fragment> FragmentTestRule<?,F> create(java.lang.Class<F> fragmentClass, boolean initialTouchMode, boolean launchFragment)
FragmentTestRule for the Fragment under test.
This factory uses a standard Activity to launch the fragment. If you need a special Activity use the constructors.
fragmentClass - The fragment under testinitialTouchMode - true if the Activity should be placed into "touch mode" when startedlaunchFragment - true if the Fragment should be launched once per
Test method. It will be launched before the first
Before method, and terminated after the last
After method.FragmentTestRule(Class, Class, boolean, boolean, boolean)protected void afterActivityLaunched()
public void launchFragment(F fragment)
Don't call this method directly, unless you explicitly requested not to lazily launch the
Fragment manually using the launchFragment flag in
FragmentTestRule(Class, Class, boolean, boolean, boolean).
Usage:
@Test
public void customIntentToStartActivity() {
Fragment fragment = MyFragment.newInstance();
fragmentRule.launchFragment(fragment);
}
fragment - The Fragment under test. If fragment is null, the fragment returned
by createFragment() is used.createFragment()protected F createFragment()
The default Fragment (if this method returns null or is not overwritten) is: fragmentClass.newInstance()
public F getFragment()