Skip to content

Conversation

@joreilly
Copy link
Owner

No description provided.

claude and others added 5 commits October 24, 2025 19:16
This commit adds comprehensive UI tests for Compose Multiplatform components
that can run across Android, iOS, Desktop, and Web platforms.

Changes:
- Add compose.uiTest dependency to commonTest in build.gradle.kts
- Create PeopleInSpaceRepositoryFake for consistent test data
- Add ComposeMultiplatformUiTests.kt: Basic UI component tests for CoordinateDisplay
- Add ISSPositionUiTests.kt: Tests for ISS position display with realistic data
- Add ViewModelUiTests.kt: Advanced tests demonstrating ViewModel integration
- Add TestTagExampleTests.kt: Best practices for using test tags in UI tests
- Add comprehensive README.md documenting the testing approach and patterns

The tests use runComposeUiTest instead of platform-specific createComposeRule,
allowing them to run on multiple platforms. They demonstrate:
- Testing simple composables and complex UI components
- Integration with ViewModels and StateFlow
- Test tag usage and best practices
- Coroutine test dispatcher management
- Data-driven testing patterns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
This commit adds CI/CD workflows to automatically run the Compose Multiplatform
UI tests on pull requests and pushes to main/master branches.

New Workflows:

1. compose-ui-tests.yml (Recommended for fast feedback)
   - Runs Compose UI tests on JVM platform
   - Executes in ~3 minutes for quick feedback
   - Uploads test results as artifacts (7 day retention)
   - Publishes detailed test reports with pass/fail info
   - Uses Gradle caching for optimal performance
   - Includes concurrency control to cancel outdated runs

2. multiplatform-tests.yml (Comprehensive platform coverage)
   - Runs tests on all supported platforms:
     * JVM (ubuntu-24.04)
     * Android (ubuntu-24.04, Robolectric)
     * iOS (macos-14, simulator arm64)
     * WebAssembly (ubuntu-24.04)
   - Includes test summary job aggregating all results
   - Uploads platform-specific test result artifacts
   - Executes in ~10-15 minutes

3. README.md
   - Comprehensive documentation of all workflows
   - Guidance on choosing between fast vs comprehensive tests
   - Local testing commands and troubleshooting tips
   - Best practices for adding new tests

Features:
- Parallel test execution where possible
- Artifact uploads for debugging test failures
- JUnit XML report generation
- Concurrency control to save CI resources
- Gradle caching for faster builds
- Clear test result visualization in PR checks

The workflows automatically run tests from common/src/commonTest including:
- ComposeMultiplatformUiTests.kt
- ISSPositionUiTests.kt
- ViewModelUiTests.kt
- TestTagExampleTests.kt

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Add @OptIn(ExperimentalTestApi::class) annotation to all test classes
to suppress "This testing API is experimental and is likely to be changed
or removed entirely" warnings.

Changes:
- Add @OptIn(ExperimentalTestApi::class) to ComposeMultiplatformUiTests
- Add @OptIn(ExperimentalTestApi::class) to ISSPositionUiTests
- Add @OptIn(ExperimentalTestApi::class) to TestTagExampleTests
- Add @OptIn(ExperimentalTestApi::class) to ViewModelUiTests
- Update README.md with documentation about the opt-in requirement
- Update all code examples in README to include the annotation
- Add note explaining why the annotation is needed

The annotation is required because the Compose Multiplatform UI testing
framework (runComposeUiTest) is currently experimental. This is standard
practice when using experimental APIs and does not affect test functionality.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Rewrote ViewModelUiTests to use StateFlow-based testing instead of
attempting to instantiate ViewModels directly. The ViewModels in this
project use Koin dependency injection and don't accept constructor
parameters, which was causing "Too many arguments for constructor" errors.

Changes:

ViewModelUiTests.kt:
- Removed attempts to instantiate ViewModels with repository parameters
- Changed to StateFlow-based testing pattern using MutableStateFlow
- Added new tests demonstrating state transitions (Loading → Success → Error)
- Added test for ISS position state updates
- Added tests for all PersonListUiState variants (Loading, Success, Error)
- Added test demonstrating state transition from Loading to Success
- Updated documentation in comments to explain the testing approach
- All test composables now accept StateFlow parameters instead of ViewModels

New test coverage:
- testISSPositionDisplay_withStateFlow
- testISSPositionUpdate_whenStateChanges
- testPersonListSuccess_displaysData
- testPersonListLoading_displaysLoadingIndicator
- testPersonListError_displaysError
- testPersonListDisplaysCorrectCount
- testPersonListStateTransition_fromLoadingToSuccess

README.md:
- Updated ViewModelUiTests description to reflect state-based testing
- Added new section "Testing State-Based UI Components"
- Replaced ViewModel instantiation examples with StateFlow examples
- Added explanation of why StateFlow is used instead of actual ViewModels
- Updated code examples to show state transition testing
- Added note about Koin dependency injection in ViewModels

Benefits of this approach:
- Tests the UI layer independently of ViewModel implementation
- No need to set up complex Koin test modules
- More focused on UI behavior rather than ViewModel internals
- Easier to test different state scenarios
- Demonstrates practical testing patterns for StateFlow-based UIs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@joreilly joreilly force-pushed the claude/multiplatform-ui-tests-011CUSYuGiuNEE2C6VpwnhTb branch from b6f49c8 to edec1f2 Compare October 25, 2025 15:24
@joreilly joreilly merged commit bf36c4e into main Oct 25, 2025
7 checks passed
@joreilly joreilly deleted the claude/multiplatform-ui-tests-011CUSYuGiuNEE2C6VpwnhTb branch October 25, 2025 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants