Skip to content

Segregating the tests in android

Devrath edited this page May 16, 2021 · 1 revision

Identifying the types of tests

  • JVM-TEST ------> The android application runs on Java-Virtual-Machine.
  • DEVICE-TEST ---> But an android application uses the resources of an android device to perform some tasks.

JVM-TEST

  • We can write all our logic computation that involves things like the business logic.
  • We can use the unit test for these types of tests.
  • We can literally write thousands of these types of tests.
  • They take in terms of milliseconds to run and are the fastest of all the tests.
  • If we follow architectural patterns like MVVM, MVP, We can encapsulate the business logic in presenter or ViewModel, and then in the constructor of the presenter and ViewModel we can provide the android framework dependent dependencies.
  • Now when testing them we can just MOCK these dependencies and test the business logic that depends on the dependencies in the constructor.
  • We write all these tests in the /test folder of android.
  • We can use J-Unit software to write unit tests.
  • We can test the presenter or view-model because there is a interface seperating the view and the model
  • [VIEW] <-> Interface <-> [Presenter/ViewModel] <-> Interface <-> [Model]

DEVICE-TEST

  • One specific indicator for identifying the device tests also called Instrumentation tests is the need for context.
  • Context is needed to access any of the resource of a android device.
  • The need of the use of Asset-Manager,Sqlite-Database, all depend on the Instrumentation test
  • It needs time to run, because the apk need to be installed on the device/emulator and need to be run.
  • Instrumentation also involves performing the touch, click, typing actions on the application.
  • It involves activities, fragments which are visual UI emements.
  • We can use espresso to run UI tests
Clone this wiki locally