Skip to content

Commit caf8dfe

Browse files
stuartmorgan-gfotiDim
authored andcommitted
[flutter_plugin_tools] Replace xctest and java-test with native-test (flutter#4176)
Creates a new `native-test` command that will be used to run native unit and UI/integration tests for all platforms over time. This replaces both `xctest` and `java-test`. For CI we can continue to run each platform separately for clarity, but the combined command makes it easier to use (and remember how to use) for local development, as well as avoiding the need to introduce several new commands for desktop testing as support for that is added to the tool. Fixes flutter/flutter#84392 Fixes flutter/flutter#86489
1 parent ca6089c commit caf8dfe

11 files changed

+1491
-1202
lines changed

.cirrus.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ task:
125125
memory: 12G
126126
matrix:
127127
### Android tasks ###
128-
- name: build-apks+java-test+firebase-test-lab
128+
- name: build-apks+android-unit+firebase-test-lab
129129
env:
130130
matrix:
131131
PLUGIN_SHARDING: "--shardIndex 0 --shardCount 4"
@@ -160,13 +160,15 @@ task:
160160
- export CIRRUS_CHANGE_MESSAGE=""
161161
- export CIRRUS_COMMIT_MESSAGE=""
162162
- ./script/tool_runner.sh build-examples --apk
163-
java_test_script:
163+
native_unit_test_script:
164164
# Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they
165165
# might include non-ASCII characters which makes Gradle crash.
166166
# TODO(stuartmorgan): See https://github.com/flutter/flutter/issues/24935
167167
- export CIRRUS_CHANGE_MESSAGE=""
168168
- export CIRRUS_COMMIT_MESSAGE=""
169-
- ./script/tool_runner.sh java-test # must come after apk build
169+
# Native integration tests are handled by firebase-test-lab below, so
170+
# only run unit tests.
171+
- ./script/tool_runner.sh native-test --android --no-integration # must come after apk build
170172
firebase_test_lab_script:
171173
# Unsetting CIRRUS_CHANGE_MESSAGE and CIRRUS_COMMIT_MESSAGE as they
172174
# might include non-ASCII characters which makes Gradle crash.
@@ -239,12 +241,12 @@ task:
239241
- ./script/tool_runner.sh build-examples --ios
240242
xcode_analyze_script:
241243
- ./script/tool_runner.sh xcode-analyze --ios
242-
xctest_script:
243-
- ./script/tool_runner.sh xctest --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest"
244+
native_test_script:
245+
- ./script/tool_runner.sh native-test --ios --ios-destination "platform=iOS Simulator,name=iPhone 11,OS=latest"
244246
drive_script:
245247
# `drive-examples` contains integration tests, which changes the UI of the application.
246248
# This UI change sometimes affects `xctest`.
247-
# So we run `drive-examples` after `xctest`, changing the order will result ci failure.
249+
# So we run `drive-examples` after `native-test`; changing the order will result ci failure.
248250
- ./script/tool_runner.sh drive-examples --ios --exclude $PLUGINS_TO_EXCLUDE_INTEGRATION_TESTS
249251
### macOS desktop tasks ###
250252
- name: build_all_plugins_macos
@@ -269,7 +271,7 @@ task:
269271
- ./script/tool_runner.sh build-examples --macos
270272
xcode_analyze_script:
271273
- ./script/tool_runner.sh xcode-analyze --macos
272-
xctest_script:
273-
- ./script/tool_runner.sh xctest --macos --exclude $PLUGINS_TO_EXCLUDE_MACOS_XCTESTS
274+
native_test_script:
275+
- ./script/tool_runner.sh native-test --macos --exclude $PLUGINS_TO_EXCLUDE_MACOS_XCTESTS
274276
drive_script:
275277
- ./script/tool_runner.sh drive-examples --macos

script/tool/CHANGELOG.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@
22

33
- Added an `xctest` flag to select specific test targets, to allow running only
44
unit tests or integration tests.
5-
- Split Xcode analysis out of `xctest` and into a new `xcode-analyze` command.
5+
- **Breaking change**: Split Xcode analysis out of `xctest` and into a new
6+
`xcode-analyze` command.
67
- Fixed a bug that caused `firebase-test-lab` to hang if it tried to run more
78
than one plugin's tests in a single run.
89
- **Breaking change**: If `firebase-test-lab` is run on a package that supports
910
Android, but for which no tests are run, it now fails instead of skipping.
1011
This matches `drive-examples`, as this command is what is used for driving
1112
Android Flutter integration tests on CI.
13+
- **Breaking change**: Replaced `xctest` with a new `native-test` command that
14+
will eventually be able to run native unit and integration tests for all
15+
platforms.
16+
- Adds the ability to disable test types via `--no-unit` or
17+
`--no-integration`.
18+
- **Breaking change**: Replaced `java-test` with Android unit test support for
19+
the new `native-test` command.
1220

1321
## 0.4.1
1422

script/tool/README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,28 @@ cd <repository root>
7575
dart run ./script/tool/bin/flutter_plugin_tools.dart test --packages plugin_name
7676
```
7777

78-
### Run XCTests
78+
### Run Dart Integration Tests
7979

8080
```sh
8181
cd <repository root>
82-
# For iOS:
83-
dart run ./script/tool/bin/flutter_plugin_tools.dart xctest --ios --packages plugin_name
84-
# For macOS:
85-
dart run ./script/tool/bin/flutter_plugin_tools.dart xctest --macos --packages plugin_name
82+
dart run ./script/tool/bin/flutter_plugin_tools.dart build-examples --packages plugin_name
83+
dart run ./script/tool/bin/flutter_plugin_tools.dart drive-examples --packages plugin_name
84+
```
85+
86+
### Run Native Tests
87+
88+
`native-test` takes one or more platform flags to run tests for. By default it
89+
runs both unit tests and (on platforms that support it) integration tests, but
90+
`--no-unit` or `--no-integration` can be used to run just one type.
91+
92+
Examples:
93+
94+
```sh
95+
cd <repository root>
96+
# Run just unit tests for iOS and Android:
97+
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --ios --android --no-integration --packages plugin_name
98+
# Run all tests for macOS:
99+
dart run ./script/tool/bin/flutter_plugin_tools.dart native-test --macos --packages plugin_name
86100
```
87101

88102
### Publish a Release

script/tool/lib/src/common/package_looping_command.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ abstract class PackageLoopingCommand extends PluginCommand {
165165
final List<String> components = p.posix.split(packageName);
166166
// For the common federated plugin pattern of `foo/foo_subpackage`, drop
167167
// the first part since it's not useful.
168-
if (components.length == 2 &&
168+
if (components.length >= 2 &&
169169
components[1].startsWith('${components[0]}_')) {
170-
packageName = components[1];
170+
packageName = p.posix.joinAll(components.sublist(1));
171171
}
172172
return packageName;
173173
}

script/tool/lib/src/java_test_command.dart

Lines changed: 0 additions & 78 deletions
This file was deleted.

script/tool/lib/src/main.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ import 'create_all_plugins_app_command.dart';
1515
import 'drive_examples_command.dart';
1616
import 'firebase_test_lab_command.dart';
1717
import 'format_command.dart';
18-
import 'java_test_command.dart';
1918
import 'license_check_command.dart';
2019
import 'lint_podspecs_command.dart';
2120
import 'list_command.dart';
21+
import 'native_test_command.dart';
2222
import 'publish_check_command.dart';
2323
import 'publish_plugin_command.dart';
2424
import 'pubspec_check_command.dart';
2525
import 'test_command.dart';
2626
import 'version_check_command.dart';
2727
import 'xcode_analyze_command.dart';
28-
import 'xctest_command.dart';
2928

3029
void main(List<String> args) {
3130
const FileSystem fileSystem = LocalFileSystem();
@@ -51,17 +50,16 @@ void main(List<String> args) {
5150
..addCommand(DriveExamplesCommand(packagesDir))
5251
..addCommand(FirebaseTestLabCommand(packagesDir))
5352
..addCommand(FormatCommand(packagesDir))
54-
..addCommand(JavaTestCommand(packagesDir))
5553
..addCommand(LicenseCheckCommand(packagesDir))
5654
..addCommand(LintPodspecsCommand(packagesDir))
5755
..addCommand(ListCommand(packagesDir))
56+
..addCommand(NativeTestCommand(packagesDir))
5857
..addCommand(PublishCheckCommand(packagesDir))
5958
..addCommand(PublishPluginCommand(packagesDir))
6059
..addCommand(PubspecCheckCommand(packagesDir))
6160
..addCommand(TestCommand(packagesDir))
6261
..addCommand(VersionCheckCommand(packagesDir))
63-
..addCommand(XcodeAnalyzeCommand(packagesDir))
64-
..addCommand(XCTestCommand(packagesDir));
62+
..addCommand(XcodeAnalyzeCommand(packagesDir));
6563

6664
commandRunner.run(args).catchError((Object e) {
6765
final ToolExit toolExit = e as ToolExit;

0 commit comments

Comments
 (0)