Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. // MainActivityTest.java
  2.  
  3. // Static imports for assertion methods
  4. import static junit.framework.Assert.assertNotNull;
  5. import static junit.framework.Assert.assertTrue;
  6.  
  7. @Config(constants = BuildConfig.class, sdk = Build.VERSION_CODES.LOLLIPOP)
  8. @RunWith(RobolectricTestRunner.class)
  9. public class MainActivityTest {
  10. private MainActivity activity;
  11.  
  12. // @Before => JUnit 4 annotation that specifies this method should run before each test is run
  13. // Useful to do setup for objects that are needed in the test
  14. @Before
  15. public void setup() {
  16. // Convenience method to run MainActivity through the Activity Lifecycle methods:
  17. // onCreate(...) => onStart() => onPostCreate(...) => onResume()
  18. activity = Robolectric.setupActivity(MainActivity.class);
  19. }
  20.  
  21. // @Test => JUnit 4 annotation specifying this is a test to be run
  22. // The test simply checks that our TextView exists and has the text "Hello world!"
  23. @Test
  24. public void validateTextViewContent() {
  25. TextView tvHelloWorld = (TextView) activity.findViewById(R.id.tvHelloWorld);
  26. assertNotNull("TextView could not be found", tvHelloWorld);
  27. assertTrue("TextView contains incorrect text",
  28. "Hello world!".equals(tvHelloWorld.getText().toString()));
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement