Skip to content

Conversation

cartland
Copy link
Contributor

  • Documentation URL
  • Original snippet
    • N/A (multiple snippets)
  • New snippet
    • N/A (multiple snippets)
  • New snippet file
    • kotlin/src/test/java/com/android/example/flow/test/RepositoryTest.kt
    • kotlin/src/test/java/com/android/example/flow/test/ViewModelTest.kt
    • kotlin/src/test/java/com/android/example/flow/test/MainDispatcherRule.kt
    • kotlin/src/test/java/com/android/example/flow/test/TurbineTest.kt
    • kotlin/src/test/java/com/android/example/flow/test/fakes.kt
  • Modified files
    • kotlin/build.gradle.kts
    • gradle/libs.versions.toml
    • kotlin/src/test/java/com/android/example/flow/test/RepositoryTest.kt
    • GEMINI.md
  • Region tag
    • android_snippets_kotlin_flow_test_fake_repository
    • android_snippets_kotlin_flow_test_my_test
    • android_snippets_kotlin_flow_test_repository_test_first
    • android_snippets_kotlin_flow_test_repository_test_to_list
    • android_snippets_kotlin_flow_test_repository_and_datasource
    • android_snippets_kotlin_flow_test_continuously_collect
    • android_snippets_kotlin_flow_test_using_turbine
    • android_snippets_kotlin_flow_test_my_view_model
    • android_snippets_kotlin_flow_test_fake_repository_viewmodel
    • android_snippets_kotlin_flow_test_hot_fake_repository
    • android_snippets_kotlin_flow_test_my_view_model_with_state_in
    • android_snippets_kotlin_flow_test_lazily_sharing_view_model
  • Related code
    • The code snippets are located in new files because they represent a new collection of related tests. The Turbine test was moved to a separate file to improve organization.
  • Running the code snippet
    • The code can be run by executing the tests in the RepositoryTest, ViewModelTest, and TurbineTest classes. These are unit tests and can be run with the command ./gradlew :kotlin:testDebugUnitTest.
  • Git branch status
    • All changes have been committed to the current branch: cartland/flow-test-snippets.
  • git status and git diff main
    • We confirmed with git status, git log -n 2, and git diff main that the correct changes have been committed
  • Next steps
    • Review the code in the current branch cartland/flow-test-snippets
    • When you are ready to make the branch public, run
      • git push
    • Then you can create a pull request at https://github.com/android/snippets/pull/new/cartland/flow-test-snippets

This commit adds a series of snippets from the Kotlin Flow testing documentation.
It includes examples of how to test Repositories and ViewModels that expose Flows and StateFlows.

The snippets are organized into two new test files:
- RepositoryTest.kt
- ViewModelTest.kt

A MainDispatcherRule is also introduced to handle setting the main dispatcher in tests.

Region-Tag: android_snippets_kotlin_flow_test_fake_repository
Region-Tag: android_snippets_kotlin_flow_test_my_test
Region-Tag: android_snippets_kotlin_flow_test_repository_test_first
Region-Tag: android_snippets_kotlin_flow_test_repository_test_to_list
Region-Tag: android_snippets_kotlin_flow_test_repository_and_datasource
Region-Tag: android_snippets_kotlin_flow_test_continuously_collect
Region-Tag: android_snippets_kotlin_flow_test_using_turbine
Region-Tag: android_snippets_kotlin_flow_test_my_view_model
Region-Tag: android_snippets_kotlin_flow_test_fake_repository_viewmodel
Region-Tag: android_snippets_kotlin_flow_test_hot_fake_repository
Region-Tag: android_snippets_kotlin_flow_test_my_view_model_with_state_in
Region-Tag: android_snippets_kotlin_flow_test_lazily_sharing_view_model
This commit refactors the Flow testing snippets by moving the Turbine test to its own file. To avoid code duplication, the  and  classes were moved to a new  file, so they can be shared between tests.
Copy link

snippet-bot bot commented Aug 22, 2025

Here is the summary of changes.

You are about to add 11 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

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.

2 participants