Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion shell/platform/android/test/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ integration tests in other repos.
`FlutterTestSuite.java`. This makes sure the test is actually executed at
run time.
4. Write your test.
5. Build and run with `testing/run_tests.py [--type=java] [--java-filter=<test_class_name>]`.
5. Build and run with `testing/run_tests.py [--type=java] [--java-filter=<test_class_name>] [--ignore-android-deprecations]`.

## Q&A

Expand Down
9 changes: 9 additions & 0 deletions shell/platform/android/test_runner/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ apply plugin: "com.android.library"

rootProject.buildDir = project.property("build_dir")

// Shows warnings for usage of deprecated API usages unless otherwise specified.
def ignoreDeprecations = project.findProperty('ignore-deprecations')
gradle.projectsEvaluated {
if (!ignoreDeprecations.toBoolean()) {
tasks.withType(JavaCompile) {
options.compilerArgs << "-Xlint:deprecation"
}
}
}

android {
compileSdkVersion 31
Expand Down
9 changes: 7 additions & 2 deletions testing/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ def JavaBin():
return os.path.join(JavaHome(), 'bin', 'java.exe' if IsWindows() else 'java')


def RunJavaTests(filter, android_variant='android_debug_unopt'):
def RunJavaTests(filter, android_variant='android_debug_unopt', ignore_android_deprecations=False):
"""Runs the Java JUnit unit tests for the Android embedding"""
test_runner_dir = os.path.join(buildroot_dir, 'flutter', 'shell', 'platform', 'android', 'test_runner')
gradle_bin = os.path.join(buildroot_dir, 'gradle', 'bin', 'gradle.bat' if IsWindows() else 'gradle')
Expand All @@ -336,10 +336,13 @@ def RunJavaTests(filter, android_variant='android_debug_unopt'):
gradle_cache_dir = os.path.join(out_dir, android_variant, 'robolectric_tests', '.gradle')

test_class = filter if filter else 'io.flutter.FlutterTestSuite'
ignore_deprecations = 'true' if ignore_android_deprecations else ''

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could it be set in build.gradle directly, or is the flag helpful for some situations?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I only added the flag in case someone wants to hide the warnings, but I can remove the flag if you don't see a need for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@GaryQian any thoughts on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No strong opinions either way. If the warnings show up before everything else, it's unlikely people would actively turn it off, but also more customization is not that much overhead either.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Might be a bit more clear if default=True were set in the parser.add_argument rather than depend on the value being None.


command = [
gradle_bin,
'-Pflutter_jar=%s' % flutter_jar,
'-Pbuild_dir=%s' % build_dir,
'-Pignore-deprecations=%s' % ignore_deprecations,
'testDebugUnitTest',
'--tests=%s' % test_class,
'--rerun-tasks',
Expand Down Expand Up @@ -567,6 +570,8 @@ def main():
default=False, help='Provide the sanitizer suppressions lists to the via environment to the tests.')
parser.add_argument('--adb-path', dest='adb_path', action='store',
default=None, help='Provide the path of adb used for android tests. By default it looks on $PATH.')
parser.add_argument('--ignore-android-deprecations', dest='ignore_android_deprecations', help='Hide warnings concerning usage of deprecated APIs when running Android tests',
action="store_true")

args = parser.parse_args()

Expand Down Expand Up @@ -613,7 +618,7 @@ def main():
if ',' in java_filter or '*' in java_filter:
print('Can only filter JUnit4 tests by single entire class name, eg "io.flutter.SmokeTest". Ignoring filter=' + java_filter)
java_filter = None
RunJavaTests(java_filter, args.android_variant)
RunJavaTests(java_filter, args.android_variant, args.ignore_android_deprecations)

if 'android' in types:
assert not IsWindows(), "Android engine files can't be compiled on Windows."
Expand Down