Event-Based Test Framework for Android
Event-Based Test Framework for Android
The APK-based test framework for Android application testing offers several advantages. Firstly, it allows for complex test cases to be built using Android's own components (Activity, Service, etc.), making the tests more integrated and efficient . Secondly, this framework facilitates testing without requiring a computer connection, enabling tests to be conducted under actual mobile conditions . Additionally, since both the test scheduler and test cases are APKs, leveraging Android APIs provides the ability to harness Android resources effectively, such as events and messages, which enhances the ability to perform a variety of tests, including black box and performance testing . This contrasts with emulator-based methods that are mainly useful for debugging during development and do not handle external events effectively .
The use of a Service in running long-duration test cases in the proposed framework addresses challenges related to application lifecycle management and resource availability. Android applications are often subjected to lifecycle events that can terminate applications when the device faces memory constraints. By running test cases within a Service, especially a foreground Service, the framework ensures continuity of execution even under memory stress . This is crucial for long-duration tests that might run for more than 30 minutes and require stability that simple Activity-based test cases cannot offer. Additionally, the Service helps in monitoring state changes and notifications, thereby maintaining the integrity of the test case execution sequence .
The proposed framework defines three patterns for test cases: (1) Test cases made with Activity; (2) Test cases made with Activity and Service; and (3) Test cases made with Activity and Async task . Test cases using only Activity are designed for short-duration tests and are appropriate for quick checks that take 1-2 minutes, such as APK debuggable tests and Main/Sub APK tests . The Activity and Service pattern is applied for long-duration tests (over 30 minutes), benefiting from the Service's capability to continue operations under memory constraints, such as testing APK crashes where the Service prevents termination . The third pattern uses an Async task for background operations, which is suitable for scenarios involving UI automation without hindering the UI thread, like executing complex language tests .
The test scheduler in the proposed framework is an APK that orchestrates the execution of complex test cases. It uses the basic Android components such as Activity, Service, Content provider, and Broadcast receiver to invoke and manage test cases. The scheduler has interactive UI elements allowing users to select test cases for execution and provides a reset option to reinitialize their state . As test cases are also APKs, they are invoked by the scheduler sequentially. The test scheduler monitors each test case through a State update mechanism facilitated by a Content provider. It keeps track of test case statuses through four states: NotExecuted, Started, Running, and Executed . Continuous monitoring involves a Service that listens for state updates via notifications triggered by Content provider changes, ensuring that test cases are executed correctly and sequentially .
The proposed framework improves upon GUI crawling techniques by extending the scope of events considered beyond user interactions to include external events like hardware and network conditions. GUI crawling traditionally focuses on user events for regression and crash testing, often missing interactions that involve hardware and network events . The proposed framework, by using APK-based test cases and leveraging Android APIs, encompasses a broader range of events, thus providing more thorough testing capabilities that address system-level complexities like application interactions and external event handling . This enhancement allows for highly integrated and comprehensive testing scenarios that GUI crawling alone cannot achieve .
Using Android APIs within the proposed framework allows the development of complex test cases that leverage native components and capabilities of the Android platform. This includes using core Android application building blocks such as Activities, Services, Content providers, and Broadcast receivers to craft test scenarios that are deeply integrated with the system. It also allows direct access to device states, internal resources, and even user-like interactions, which can be critical for testing areas such as hardware interactions, application behavior under various conditions, and performance tests . Moreover, utilizing Android's intrinsic logging and notification systems enables comprehensive tracking and debugging, enriching the testing process by providing detailed insights into system interactions and test coverage . This direct use of native environments makes the testing robust and more in tune with real-world usage scenarios compared to frameworks reliant on simulated environments .
The proposed framework primarily focuses on testing within the Android environment by using APKs as test cases and scheduler, allowing it to exploit Android's resources and APIs fully. Unlike other frameworks that integrate multiple frameworks for cross-platform compatibility and primarily address simple test cases , the proposed framework aims to handle complex test cases specific to Android. It achieves this by fully utilizing Android's capabilities, without cross-platform dependencies, making it ideal for deep, Android-specific aspects such as internal hardware failures and interactions with Android-exclusive APIs . This approach ensures thorough and specific application testing within the Android ecosystem, rather than a generalized cross-platform solution which might compromise depth for breadth .
In the test framework, Android's Broadcast receiver serves as a communication bridge between the Activity and the Service components of the test scheduler. It processes communications, specifically when a user selects or deselects test cases in the UI. These interactions send messages from the Scheduler to the Service using registered receivers. Critical information, such as package names and checkbox statuses, are sent as 'extras' within intents managed by the Broadcast receiver . This mechanism allows the test scheduler to update important state information like Shared preferences and the Content provider, ensuring seamless coordination between various components .
The proposed Android test framework ensures state persistence using mechanisms such as Shared preferences and a Content provider. Shared preferences are used to maintain state within individual Activities, allowing for state recovery across Activity lifecycle changes, such as orientation switches . For consistency across multiple test cases, the framework employs a Content provider which acts as a centralized database (SQLite) to track the state of each test case. States like NotExecuted, Started, Running, and Executed are consistently updated to reflect the current progress, ensuring that each test case runs in sequence as intended . The use of Content observers further ensures synchronization between the Scheduler and test cases, providing notifications for any state changes, thereby maintaining execution order and consistency .
Within the proposed test framework, the content provider serves as a key element for inter-component communication by acting as a relational database using SQLite. It facilitates state management across the test scheduler and test cases, ensuring proper coordination and sequence of execution. The content provider tracks the state of each test case - NotExecuted, Started, Running, and Executed - to monitor and control progression . By enabling operations like Insert, Update, and Query, the content provider allows the scheduler and test cases to share execution status and updates efficiently, thereby facilitating continuous state monitoring. This is crucial for handling the transition of states systematically, ensuring that each component of the framework is synchronized and operates cohesively .