{"id":2555,"date":"2020-03-30T21:47:21","date_gmt":"2020-03-30T11:47:21","guid":{"rendered":"https:\/\/learntodroid.com\/?p=2555"},"modified":"2020-03-30T21:47:28","modified_gmt":"2020-03-30T11:47:28","slug":"android-testing-tools","status":"publish","type":"post","link":"http:\/\/10.0.0.14:32769\/android-testing-tools\/","title":{"rendered":"11 Useful Testing Tools, Libraries and Frameworks for Android"},"content":{"rendered":"\n

There is a large selection of different testing tools, libraries and frameworks available for Android. It is hard to understand which tool to use for what type of tests whether that is unit testing, mocking, user interface testing or integration testing.<\/p>\n\n\n\n

I have put together an article covering 11 useful testing tools, libraries and frameworks to use for Android which includes the following:<\/p>\n\n\n\n

  1. JUnit 4 (unit testing framework)<\/li>
  2. Espresso (user interface testing framework)<\/li>
  3. Robolectric (testing framework which supports running testing Android components on JVM)<\/li>
  4. AndroidX Test (testing library available under Jetpack)<\/li>
  5. Hamcrest (matchers framework)<\/li>
  6. Truth (assertions library)<\/li>
  7. Mockito (mocking framework)<\/li>
  8. Firebase Test Lab (tool running tests on your Android app on a physical or virtual device in the cloud)<\/li>
  9. Firebase App Distribution (tool for distributing mobile app builds to testers) <\/li>
  10. UI Automator (user interface testing tool for interactions across multiple apps)<\/li>
  11. Appium (test automation framework based on WebDriver protocol)<\/li><\/ol>\n\n\n\n

    For each tool I will cover some information about where it is best used for testing an Android app, how to get started retrieving any dependencies along with any test class code samples where applicable.<\/p>\n\n\n\n

    JUnit 4<\/h2>\n\n\n\n

    JUnit 4 is a popular Java based open source framework used for writing and running unit tests.<\/p>\n\n\n\n

    JUnit 4 has a feature called assertions<\/a> which allows for testing the result of actual behaviour of an application against expected behaviour. <\/p>\n\n\n\n

    Some common assertions supported by JUnit 4 are:<\/p>\n\n\n\n

    • assertEquals and assertNotEquals<\/li>
    • assertTrue and assertFalse <\/li>
    • assertNull and assertNotNull<\/li>
    • assertSame and assertNotSame <\/li>
    • assertArrayEquals<\/li>
    • assertThat<\/li><\/ul>\n\n\n\n

      JUnit 4 also features test fixtures<\/a> which provide support for sequencing tests by using annotations such as @BeforeClass, @AfterClass, @Before and @After. This is useful where you need to need to put the application into a particular state before running unit tests.<\/p>\n\n\n\n

      JUnit 4 also features test runners<\/a> which are used for executing unit tests.<\/p>\n\n\n\n

      For testing Android apps, JUnit 4 is useful for running both local unit tests (tests that run on the JVM) and instrumented unit tests (tests that run on an Android device or emulator).<\/p>\n\n\n\n

      For an example test class containing local unit tests for Android that uses JUnit 4, see the code sample below.<\/p>\n\n\n