-
Notifications
You must be signed in to change notification settings - Fork 89
[Jules] Add instrumented test for catalog app to verify app launches #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
name: Android CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
- name: Set up Android SDK | ||
uses: android-actions/setup-android@v3 # Using v3 as it's the latest | ||
with: | ||
api-level: 34 # Assuming API level 34, adjust if needed | ||
build-tools-version: 34.0.0 # Assuming build tools 34.0.0 | ||
ndk-version: 25.1.8937393 # Optional: specify NDK version if needed | ||
# cmake-version: # Optional: specify CMake version if needed | ||
|
||
- name: Grant execute permission to gradlew | ||
run: chmod +x ai-catalog/gradlew | ||
|
||
- name: Build with Gradle | ||
working-directory: ./ai-catalog | ||
run: ./gradlew build | ||
|
||
- name: Run Android Instrumented Tests | ||
working-directory: ./ai-catalog | ||
run: ./gradlew :app:connectedAndroidTest |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,6 +93,10 @@ dependencies { | |
testImplementation(libs.junit) | ||
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the This new line adds |
||
androidTestImplementation("androidx.test:runner:1.5.2") | ||
androidTestImplementation("androidx.test:rules:1.5.0") | ||
Comment on lines
+98
to
+99
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These test dependencies ( For example, you could add entries to your [versions]
# ... other versions
androidxTestRunner = "1.5.2"
androidxTestRules = "1.5.0"
[libraries]
# ... other libraries
androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidxTestRunner" }
androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = "androidxTestRules" } And then reference them here as: androidTestImplementation(libs.androidx.test.runner)
androidTestImplementation(libs.androidx.test.rules) What are your thoughts on moving these to the versions catalog for improved maintainability?
Style Guide ReferencesFootnotes
|
||
androidTestImplementation(platform(libs.androidx.compose.bom)) | ||
androidTestImplementation(libs.androidx.ui.test.junit4) | ||
debugImplementation(libs.androidx.ui.tooling) | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,26 @@ | ||||||||||
package com.google.android.apps.ai.catalog; | ||||||||||
|
||||||||||
import androidx.test.ext.junit.runners.AndroidJUnit4; | ||||||||||
import org.junit.runner.RunWith; | ||||||||||
import org.junit.Rule; | ||||||||||
import androidx.test.rule.ActivityTestRule; | ||||||||||
import com.google.android.apps.ai.catalog.MainActivity; | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There seems to be a package mismatch for the This will likely cause a compilation error. Shouldn't the import be for
Suggested change
|
||||||||||
|
||||||||||
import static androidx.test.espresso.Espresso.onView; | ||||||||||
import static androidx.test.espresso.assertion.ViewAssertions.matches; | ||||||||||
import static androidx.test.espresso.matcher.ViewMatchers.isDisplayed; | ||||||||||
import static androidx.test.espresso.matcher.ViewMatchers.withText; | ||||||||||
import org.junit.Test; | ||||||||||
|
||||||||||
@RunWith(AndroidJUnit4.class) | ||||||||||
public class MainActivityTest { | ||||||||||
|
||||||||||
@Rule | ||||||||||
public ActivityTestRule<MainActivity> activityRule = | ||||||||||
new ActivityTestRule<>(MainActivity.class); | ||||||||||
Comment on lines
+19
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you update this to use Style Guide References
Suggested change
Footnotes
|
||||||||||
|
||||||||||
@Test | ||||||||||
public void testLaunchAndFindText() { | ||||||||||
onView(withText("Android AI Samples")).check(matches(isDisplayed())); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The test assertion uses a hardcoded string "Android AI Samples". While this works, it can make the test brittle if the UI text changes or if the app is localized. It's generally a best practice to use string resources ( Could you consider the following improvements?
This would also require importing String expectedText = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().getTargetContext().getString(com.android.ai.catalog.R.string.main_activity_title); // Ensure 'main_activity_title' is defined in strings.xml and R class is correctly referenced.
onView(withText(expectedText)).check(matches(isDisplayed())); Style Guide ReferencesFootnotes
|
||||||||||
} | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears this line introduces a redundant dependency for
espresso-core
. Line 95 already includesandroidTestImplementation(libs.androidx.espresso.core)
, which, according to yourlibs.versions.toml
(espressoCore = "3.6.1"
), points to version 3.6.1.This new line adds
espresso-core:3.5.1
, which is an older version and duplicates the dependency. Could this line be removed to avoid potential version conflicts and keep dependencies streamlined via the versions catalog?