Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MainActivityTest.java
- // Static imports for assertion methods
- import static junit.framework.Assert.assertNotNull;
- import static junit.framework.Assert.assertTrue;
- @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
- @RunWith(RobolectricTestRunner.class)
- public class MainActivityTest {
- private MainActivity activity;
- // @Before => JUnit 4 annotation that specifies this method should run before each test is run
- // Useful to do setup for objects that are needed in the test
- @Before
- public void setup() {
- // Convenience method to run MainActivity through the Activity Lifecycle methods:
- // onCreate(...) => onStart() => onPostCreate(...) => onResume()
- activity = Robolectric.setupActivity(MainActivity.class);
- }
- // @Test => JUnit 4 annotation specifying this is a test to be run
- // The test simply checks that our TextView exists and has the text "Hello world!"
- @Test
- public void validateTextViewContent() {
- TextView tvHelloWorld = (TextView) activity.findViewById(R.id.tvHelloWorld);
- assertNotNull("TextView could not be found", tvHelloWorld);
- assertTrue("TextView contains incorrect text",
- "Hello world!".equals(tvHelloWorld.getText().toString()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement