This document describes the comprehensive UI tests added to the MVI Coroutines Flow Android application.
The UI tests are built using:
- AndroidJUnit4 for test execution
- Espresso for UI interactions and assertions
- ActivityScenarioRule for activity lifecycle management
- Intent testing for navigation verification
-
MainActivityUITest (ExampleInstrumentedTest.kt)
- Tests user list display via RecyclerView
- Tests SwipeRefreshLayout pull-to-refresh functionality
- Tests menu navigation to Add and Search activities
- Tests error states and retry functionality
-
NavigationUITest
- Tests Intent-based navigation from MainActivity to AddActivity
- Tests Intent-based navigation from MainActivity to SearchActivity
- Uses Espresso Intents for verification
-
AddActivityUITest
- Tests form field display and input handling
- Tests form validation for email, first name, last name
- Tests add button functionality and validation errors
-
SearchActivityUITest
- Tests SearchView display and interaction
- Tests search input and submission
- Tests search results RecyclerView display
-
IntegrationUITest
- Tests complete end-to-end user flows
- Tests navigation between multiple activities
- Tests form filling and search workflows
- Tests swipe-to-refresh integration
-
feature-main (
feature-main/src/androidTest/)- MainActivityUITest: Module-specific tests for MainActivity
-
feature-add (
feature-add/src/androidTest/)- AddActivityUITest: Module-specific tests for AddActivity form functionality
-
feature-search (
feature-search/src/androidTest/)- SearchActivityUITest: Module-specific tests for SearchActivity search functionality
- ✅ RecyclerView with user list
- ✅ SwipeRefreshLayout
- ✅ TextInputLayout form fields
- ✅ SearchView in ActionBar
- ✅ Material buttons and progress indicators
- ✅ Error states and retry buttons
- ✅ Navigation drawer/menu
- ✅ Pull-to-refresh gestures
- ✅ Text input and form validation
- ✅ Menu navigation
- ✅ Search input and submission
- ✅ Button clicks and form submission
- ✅ Back navigation
- ✅ Intent-based navigation between activities
- ✅ Form validation errors (invalid email, empty fields)
- ✅ Network error states with retry functionality
- ✅ Loading states and progress indicators
- Android device or emulator connected
- App built in debug mode
# Run all UI tests
./gradlew connectedAndroidTest
# Run specific module tests
./gradlew app:connectedAndroidTest
./gradlew feature-main:connectedAndroidTest
./gradlew feature-add:connectedAndroidTest
./gradlew feature-search:connectedAndroidTest
# Run specific test class
./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.hoc.flowmvi.MainActivityUITest
# Run with coverage
./gradlew app:connectedAndroidTest koverGenerateXmlReport- Right-click on test class or method
- Select "Run 'TestName'"
- View results in Test Results panel
The following dependencies were added to support comprehensive UI testing:
// Core testing framework
androidTestImplementation(libs.androidx.test.junit.ktx)
androidTestImplementation(libs.androidx.test.core.ktx)
androidTestImplementation(libs.androidx.test.rules)
// Espresso UI testing
androidTestImplementation(libs.androidx.test.espresso.core)
androidTestImplementation(libs.androidx.test.espresso.contrib)
androidTestImplementation(libs.androidx.test.espresso.intents)- Page Object Pattern: Consider implementing page objects for complex screens
- Test Data: Use consistent test data across tests
- Isolation: Each test should be independent and not rely on others
- Assertions: Use specific assertions rather than generic ones
- Timing: Use Espresso's built-in waiting mechanisms instead of Thread.sleep()
- Network Dependencies: Some tests may require network mocking for consistent results
- State Management: Tests assume certain initial states of the app
- Device Dependencies: Some gestures may behave differently on different devices
- Build Configuration: Tests require the app to be in a testable state (debug build)
- Network Mocking: Add OkHttp MockWebServer for network request testing
- Test Data Factory: Implement test data builders for consistent test data
- Screenshot Testing: Add screenshot comparison testing
- Performance Testing: Add UI performance benchmarking
- Accessibility Testing: Add accessibility verification tests
- Cross-platform Testing: Extend tests for different device configurations
- Resource ID not found: Ensure the correct module context and R.id references
- Activity not found: Verify activity is exported and properly configured
- Test timeouts: Increase timeout values for slow operations
- Flaky tests: Add proper waits and state verification
- Enable verbose logging with
adb logcat - Use Espresso's layout hierarchy dumps
- Add screenshot capture on test failure
- Use debugging mode to step through test execution