Created
February 27, 2017 00:04
-
-
Save abatilo/4b6111d9e12058b3573f87df8cb44d6d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(AndroidJUnit4.class) public class FragmentTest { | |
// Setup an ActivityTestRule as such that the Activity is not launched until we say so | |
@Rule public ActivityTestRule<EmptyActivity> rule = | |
new ActivityTestRule<>(EmptyActivity.class, true, false); | |
private Fragment fragment; | |
private EmptyActivity activity; | |
@Before public void setup() { | |
// Setup shared mock information or do your dependency injection | |
fragment = new YourFragment(); | |
} | |
@Test public void fragmentTest() { | |
// Setup your test specific mocks here | |
activity = rule.launchActivity(new Intent()); | |
activity.getSupportFragmentManager() | |
.beginTransaction() | |
.replace(R.id.fragment, fragment) | |
.commit(); | |
// Write your assertions here | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment