Skip to content

Add runComposeUiTest API snippets#789

Open
hiichoudhary wants to merge 4 commits intomainfrom
hiichoudhary/test-v2-apis
Open

Add runComposeUiTest API snippets#789
hiichoudhary wants to merge 4 commits intomainfrom
hiichoudhary/test-v2-apis

Conversation

@hiichoudhary
Copy link
Collaborator

Add snippets for runComposeUiTest API usage.

@hiichoudhary hiichoudhary requested a review from riggaroo February 4, 2026 09:55
@hiichoudhary hiichoudhary self-assigned this Feb 4, 2026
@hiichoudhary hiichoudhary requested a review from a team as a code owner February 4, 2026 09:55
@snippet-bot
Copy link

snippet-bot bot commented Feb 4, 2026

Here is the summary of changes.

You are about to add 2 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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @hiichoudhary, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces new code snippets to the compose/snippets module, specifically focusing on best practices for testing Jetpack Compose UI with coroutines. It provides a clear example of how to effectively use the runComposeUiTest API for time-sensitive tests and highlights a common pitfall when integrating runTest with standard Compose test rules.

Highlights

  • New runComposeUiTest API Snippet: A new code snippet has been added to demonstrate the correct usage of the runComposeUiTest API for testing Jetpack Compose UI components that involve coroutines and time-based operations, such as delay.
  • Illustrative runTest with createComposeRule Snippet: An additional snippet illustrates a common pitfall when using runTest alongside createComposeRule for coroutine-based tests, explaining why it fails due to separate schedulers and suggesting a solution.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • compose/snippets/src/androidTest/java/com/example/compose/snippets/test/TestSnippets.kt
    • Added a new file containing two distinct code snippets for Compose UI testing.
    • Included a snippet demonstrating the runComposeUiTest API for testing coroutine-driven UI updates.
    • Provided a 'NOT RECOMMENDED' snippet illustrating issues with runTest and createComposeRule when dealing with coroutine schedulers.
Activity
  • No specific activity has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds useful snippets for runComposeUiTest, including a positive example and a common pitfall. The code is clear and serves its purpose well. I have a couple of suggestions to improve readability and maintainability by renaming a class for clarity and addressing a magic number.

}

onNodeWithText("Loading...").assertIsDisplayed()
mainClock.advanceTimeBy(1000 + 16 /* Frame buffer */)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve readability and avoid magic numbers, consider extracting 16 into a named constant, for example FRAME_BUFFER_MS. While there is a comment, using a constant makes the code's intent clearer and is generally a better practice.

}
// [END android_compose_test_runComposeUiTest]

class Test2 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The class name Test2 is not descriptive. For better readability, especially in a file with multiple test classes, consider renaming it to something that reflects its purpose. A more descriptive name would make it easier to understand that this class demonstrates a common pitfall.

Suggested change
class Test2 {
class IncorrectCoroutineTestExample {

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