Skip to content

[tool] Add support for using a Kotlin test runner file #6131

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

Merged
merged 5 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 10 additions & 2 deletions script/tool/lib/src/firebase_test_lab_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -360,8 +360,16 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
.where((FileSystemEntity entity) => entity is File)
.cast<File>()
.any((File file) {
return file.basename.endsWith('.java') &&
file.readAsStringSync().contains('@RunWith(FlutterTestRunner.class)');
if (file.basename.endsWith('.java')) {
return file
.readAsStringSync()
.contains('@RunWith(FlutterTestRunner.class)');
} else if (file.basename.endsWith('.kt')) {
return file
.readAsStringSync()
.contains('@RunWith(FlutterTestRunner::class)');
}
return false;
});
}
}
42 changes: 42 additions & 0 deletions script/tool/test/firebase_test_lab_command_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,48 @@ public class MainActivityTest {
);
});

test('supports kotlin implementation of integration_test runner', () async {
const String kotlinTestFileRelativePath =
'example/android/app/src/androidTest/MainActivityTest.kt';
final RepositoryPackage plugin =
createFakePlugin('plugin', packagesDir, extraFiles: <String>[
'test/plugin_test.dart',
'example/integration_test/foo_test.dart',
'example/android/gradlew',
kotlinTestFileRelativePath,
]);

// Kotlin equivalent of the test runner
childFileWithSubcomponents(
plugin.directory, p.posix.split(kotlinTestFileRelativePath))
.writeAsStringSync('''
@DartIntegrationTest
@RunWith(FlutterTestRunner::class)
class MainActivityTest {
@JvmField @Rule var rule = ActivityTestRule(MainActivity::class.java)
}
''');

final List<String> output = await runCapturingPrint(
runner,
<String>[
'firebase-test-lab',
'--results-bucket=a_bucket',
'--device',
'model=redfin,version=30',
],
);

expect(
output,
containsAllInOrder(<Matcher>[
contains('Running for plugin'),
contains('Testing example/integration_test/foo_test.dart...'),
contains('Ran for 1 package')
]),
);
});

test('skips packages with no android directory', () async {
createFakePackage('package', packagesDir, extraFiles: <String>[
'example/integration_test/foo_test.dart',
Expand Down