Skip to content

Commit c56c12d

Browse files
[tool] Add support for using a Kotlin test runner file (flutter#6131)
1 parent cc05af8 commit c56c12d

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

script/tool/lib/src/firebase_test_lab_command.dart

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -360,8 +360,16 @@ class FirebaseTestLabCommand extends PackageLoopingCommand {
360360
.where((FileSystemEntity entity) => entity is File)
361361
.cast<File>()
362362
.any((File file) {
363-
return file.basename.endsWith('.java') &&
364-
file.readAsStringSync().contains('@RunWith(FlutterTestRunner.class)');
363+
if (file.basename.endsWith('.java')) {
364+
return file
365+
.readAsStringSync()
366+
.contains('@RunWith(FlutterTestRunner.class)');
367+
} else if (file.basename.endsWith('.kt')) {
368+
return file
369+
.readAsStringSync()
370+
.contains('@RunWith(FlutterTestRunner::class)');
371+
}
372+
return false;
365373
});
366374
}
367375
}

script/tool/test/firebase_test_lab_command_test.dart

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,48 @@ public class MainActivityTest {
564564
);
565565
});
566566

567+
test('supports kotlin implementation of integration_test runner', () async {
568+
const String kotlinTestFileRelativePath =
569+
'example/android/app/src/androidTest/MainActivityTest.kt';
570+
final RepositoryPackage plugin =
571+
createFakePlugin('plugin', packagesDir, extraFiles: <String>[
572+
'test/plugin_test.dart',
573+
'example/integration_test/foo_test.dart',
574+
'example/android/gradlew',
575+
kotlinTestFileRelativePath,
576+
]);
577+
578+
// Kotlin equivalent of the test runner
579+
childFileWithSubcomponents(
580+
plugin.directory, p.posix.split(kotlinTestFileRelativePath))
581+
.writeAsStringSync('''
582+
@DartIntegrationTest
583+
@RunWith(FlutterTestRunner::class)
584+
class MainActivityTest {
585+
@JvmField @Rule var rule = ActivityTestRule(MainActivity::class.java)
586+
}
587+
''');
588+
589+
final List<String> output = await runCapturingPrint(
590+
runner,
591+
<String>[
592+
'firebase-test-lab',
593+
'--results-bucket=a_bucket',
594+
'--device',
595+
'model=redfin,version=30',
596+
],
597+
);
598+
599+
expect(
600+
output,
601+
containsAllInOrder(<Matcher>[
602+
contains('Running for plugin'),
603+
contains('Testing example/integration_test/foo_test.dart...'),
604+
contains('Ran for 1 package')
605+
]),
606+
);
607+
});
608+
567609
test('skips packages with no android directory', () async {
568610
createFakePackage('package', packagesDir, extraFiles: <String>[
569611
'example/integration_test/foo_test.dart',

0 commit comments

Comments
 (0)