Journal for Developers

Getting Started with Android Testing

Android Testing - Unit vs Connected
0 93

Notice: Undefined index: rate in /home/content/p3pnexwpnas11_data03/84/3795084/html/wp-content/themes/publisher/includes/functions.php on line 5360
1 min read

While developing Android apps we can use two main types of tests.

  • Unit Tests
  • Connected Tests

The primary distinction between these two are described below:

Unit Tests

  1. Run on a regular Java JVM on your computer.
  2. They are generally used to test generic Non-Android related classes.
  3. Any code that calls the Android API will fail, since Unit tests are run against the mock Android SDK implementation. In this case, one should either a mocking framework like MOCKITO to mock the appropriate Android dependencies or use a Connected test instead.
  4. Additionally you can configure the testing option in the Gradle build script to instruct the mock Android implementation to return the default values rather than throw an error.

Connected Tests

  1. Run on an Android Device or Emulator.
  2. Should be reserved for testing logic that depends on Android APIs or for high-level testing like integration and functional tests.
  3. Connected tests are packaged as an APK that will be installed on an Android device or Emulator. So there is typically more overhead involved in the execution.

In any case, it’s up to the developers to decide how to best write the tests and how to structure the code in such a way to make testing easier.

Both Unit and Connected tests have their own source sets

UNIT = /src/test

CONNECTED = /src/androidTest

 

Subscribe to our Journal

Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!