Android Development

Google's android guide Home Contact

Android Test Automation

Android automation testing encompasses the automated verification of Android applications to ensure they meet functional, performance, and usability requirements. This testing process involves utilizing software tools and frameworks to simulate user interactions and assess the behavior of the application under diverse conditions. It can be categorized as functional or unit testing. Functional testing specifically focuses on validating the overall behavior of the application, including its individual components or features. On the other hand, unit testing concentrates on testing individual units or modules of the application in isolation to verify their correctness and robustness. Both types of testing are important for ensuring the quality and reliability of Android applications.

    Unit Testing

    Verify the small testable unit, such as method or class. They can be of two types:

    1. Local Unit Tests - Run on local machine. API dependecies are mocked.
    2. Instrumented Unit Tests - Run on emulator or android device. API dependencies are needed to have access to instrumentation information (such as context). Mocking can optionally be used only, if dependencies can suitably be mocked.

    Android Unit Testing Mocking Frameworks

    Mockito

    This is Mocking framework which can be used with Junit. Mockito dependency need to be added to the build.gradle file. Where methods can't be mocked from certain classes, another unit testing framework, Roboelectric can be used to complement it.

    Mockito can be used to create Mock objects as dummy implementation of class or interface, which are part of android framework, defined for certain behavior, recording and interactions verifications with the system.

    Mocking Examples:

  • Mocking data source.
  • Mocking file server
  • Mocking class Context.
  • Mocking Views.

  • Other then mocking objects, Stubs and Spies can also be used.

    Mockito do no test static classes. They can be converted to Singletons for Mockito to work. PowerMock can be used to mock static clases. Mockio cannot mock final classes, inner classes and anonymous classes.

    After integarting the mockito in the gradle, appropriate annotations can be used to create mocks, such as:

    • @Mock - Create mock objects.

    • @Spy - Mocking methods in real objects.

    • @Verify - To verify if method has been exceusted, once, more then once or never.

    • @doReturn - Return a specific value when calling an object method.

    • @doThrow - Throw an exception when calling an object method.

    Roboelectric

  • Run unit tests directly on JVM without any need of emulator or device, giving much faster execution time.
  • API dependencies are rewritten by using shadow classes, that extend or modify the behavior of classes in android SDK.