Android: Fundamental of testing summary

Android: Fundamental of testing summary

https://developer.android.com/training/testing/fundamentals

1) Develop your code in terms of modules

2) Each module should have only one area of focus (a specific task that users complete within your app)

3) the APIs that allow for inter-module communication should be consistent

4) AndroidTest directory should contain the tests that run on real or virtual devices.

5) The test directory should contain the tests that run on your local machine, such as unit tests.

6) Level of test

  • Small tests are unit tests that validate your app's behavior, one class, at a time (Local unit tests / Instrumented unit tests)
  • Medium tests are integration tests that validate either interactions between levels of the stack within a module, or interactions between related modules.
  • Large tests are end-to-end tests that validate user journeys spanning multiple modules of your app.

7) AndroidX Test provides a fluent assertions library called Truth as an alternative to JUnit- or Hamcrest-based assertions

8) UI tests: Espresso allows you to programmatically locate and interact with UI elements

9) AndroidJUnitRunner class lets you run JUnit 3- or JUnit 4-style test classes on Android devices.

10) UI Automator API lets you interact with visible elements on a device

11) Your app's interface should allow all users, including those with accessibility needs, to interact with the device and complete tasks more easily in your app.

- @AccessibilityChecks annotation at the beginning of your test

- Enable accessibility checks by calling AccessibilityChecks.enable() in your test suite's setUp() method

12) Use the ActivityScenario and FragmentScenario classes to test how your app's activities and fragments respond to system-level interruptions and configuration changes.

13) JUnit4 rules with AndroidX Test provide ActivityScenarioRule and ServiceTestRule

- ActivityScenarioRule : The activity under test is launched before each test annotated with @Test and before any method annotated with @Before. It's terminated after the test is completed and all methods annotated with @After are finished.

- ServiceTestRule : This rule provides a simplified mechanism to start up and shut down your service before and after your test

14) If your app's behavior depends on the device's SDK version, use the @SdkSuppress annotation, passing in values for minSdkVersion or maxSdkVersion

#aad #android #testing

To view or add a comment, sign in

More articles by Noha Samir

  • Google Android Developers Certification

    I'm officially certified by Google Developers as an Associate Android Developer (Kotlin). How can you take the exam?…

    104 Comments
  • Unit Tests

    Overview 1) A unit test generally exercises the functionality of the smallest possible unit of code (which could be a…

    14 Comments

Others also viewed

Explore content categories