[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 https://github.com/flutter/flutter/issues/93952
This commit is contained in:
stuartmorgan
2021-11-23 21:52:01 -05:00
committed by GitHub
parent 7b6ac13139
commit b25b31427a
3 changed files with 156 additions and 52 deletions

View File

@ -127,16 +127,24 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
'${example.displayName} does not support Android.');
}
if (!androidDirectory
final Directory uiTestDirectory = androidDirectory
.childDirectory('app')
.childDirectory('src')
.childDirectory('androidTest')
.existsSync()) {
.childDirectory('androidTest');
if (!uiTestDirectory.existsSync()) {
printError('No androidTest directory found.');
return PackageResult.fail(
<String>['No tests ran (use --exclude if this is intentional).']);
}
// Ensure that the Dart integration tests will be run, not just native UI
// tests.
if (!await _testsContainDartIntegrationTestRunner(uiTestDirectory)) {
printError('No integration_test runner found. '
'See the integration_test package README for setup instructions.');
return PackageResult.fail(<String>['No integration_test runner.']);
}
// Ensures that gradle wrapper exists
final GradleProject project = GradleProject(example.directory,
processRunner: processRunner, platform: platform);
@ -280,4 +288,19 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
file is File && file.basename.endsWith('_test.dart'))
.cast<File>();
}
/// Returns true if any of the test files in [uiTestDirectory] contain the
/// annotation that means that the test will reports the results of running
/// the Dart integration tests.
Future<bool> _testsContainDartIntegrationTestRunner(
Directory uiTestDirectory) async {
return uiTestDirectory
.list(recursive: true, followLinks: false)
.where((FileSystemEntity entity) => entity is File)
.cast<File>()
.any((File file) {
return file.basename.endsWith('.java') &&
file.readAsStringSync().contains('@RunWith(FlutterTestRunner.class)');
});
}
}