Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit aa80954

Browse files
[flutter_plugin_tools] Check for FlutterTestRunner in FTL tests (#4531)
When running via Firebase Test Lab, ensure that there is a test using `FlutterTestRunner`. This ensures that a plugin can't silently not run any of the Dart integration test on Android by having some other native integration test. Fixes flutter/flutter#93952
1 parent a157a0a commit aa80954

3 files changed

Lines changed: 156 additions & 52 deletions

File tree

script/tool/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## NEXT
2+
3+
- Ensures that `firebase-test-lab` runs include an `integration_test` runner.
4+
15
## 0.7.3
26

37
- `native-test` now builds unit tests before running them on Windows and Linux,

script/tool/lib/src/firebase_test_lab_command.dart

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,16 +127,24 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
127127
'${example.displayName} does not support Android.');
128128
}
129129

130-
if (!androidDirectory
130+
final Directory uiTestDirectory = androidDirectory
131131
.childDirectory('app')
132132
.childDirectory('src')
133-
.childDirectory('androidTest')
134-
.existsSync()) {
133+
.childDirectory('androidTest');
134+
if (!uiTestDirectory.existsSync()) {
135135
printError('No androidTest directory found.');
136136
return PackageResult.fail(
137137
<String>['No tests ran (use --exclude if this is intentional).']);
138138
}
139139

140+
// Ensure that the Dart integration tests will be run, not just native UI
141+
// tests.
142+
if (!await _testsContainDartIntegrationTestRunner(uiTestDirectory)) {
143+
printError('No integration_test runner found. '
144+
'See the integration_test package README for setup instructions.');
145+
return PackageResult.fail(<String>['No integration_test runner.']);
146+
}
147+
140148
// Ensures that gradle wrapper exists
141149
final GradleProject project = GradleProject(example.directory,
142150
processRunner: processRunner, platform: platform);
@@ -280,4 +288,19 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
280288
file is File && file.basename.endsWith('_test.dart'))
281289
.cast<File>();
282290
}
291+
292+
/// Returns true if any of the test files in [uiTestDirectory] contain the
293+
/// annotation that means that the test will reports the results of running
294+
/// the Dart integration tests.
295+
Future<bool> _testsContainDartIntegrationTestRunner(
296+
Directory uiTestDirectory) async {
297+
return uiTestDirectory
298+
.list(recursive: true, followLinks: false)
299+
.where((FileSystemEntity entity) => entity is File)
300+
.cast<File>()
301+
.any((File file) {
302+
return file.basename.endsWith('.java') &&
303+
file.readAsStringSync().contains('@RunWith(FlutterTestRunner.class)');
304+
});
305+
}
283306
}

0 commit comments

Comments
 (0)