Skip to content

Commit

Permalink
[tool] Add support for using a Kotlin test runner file (#6131)
Browse files Browse the repository at this point in the history
  • Loading branch information
bparrishMines authored Feb 16, 2024
1 parent cc05af8 commit c56c12d
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
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

0 comments on commit c56c12d

Please sign in to comment.