Skip to content

Commit 531852f

Browse files
committed
ci: run the iOS integration tests through XCTest (flutter/flutter#181771)
1 parent 3354e39 commit 531852f

7 files changed

Lines changed: 26 additions & 82 deletions

File tree

‎.github/scripts/ios_integration_tests.sh‎

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

‎.github/workflows/ci.yml‎

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
with:
9898
flutter-version: ${{ env.FLUTTER_VERSION }}
9999
cache: true
100-
- run: flutter build ios --simulator --debug
100+
- run: flutter pub get
101101
working-directory: example
102102
- name: Boot a simulator
103103
id: simulator
@@ -120,16 +120,12 @@ jobs:
120120
xcrun simctl privacy "$udid" grant photos dev.noegnh.filmkitPickerExample
121121
flutter devices
122122
echo "udid=$udid" >> "$GITHUB_OUTPUT"
123-
# With a watchdog that retries when flutter test misses the app's start
124-
# (flutter/flutter#181771).
123+
# Through XCTest (example/ios/RunnerTests/RunnerTests.m): flutter test often misses the
124+
# app's VM service on iOS simulators and waits forever (flutter/flutter#181771).
125125
- name: Integration tests
126126
timeout-minutes: 45
127-
run: ../.github/scripts/ios_integration_tests.sh ${{ steps.simulator.outputs.udid }}
128127
working-directory: example
129-
- name: Upload the diagnostics of hung attempts
130-
if: always()
131-
uses: actions/upload-artifact@v4
132-
with:
133-
name: ios-diagnostics
134-
path: example/build/ios_diagnostics
135-
if-no-files-found: ignore
128+
run: |
129+
flutter build ios --config-only --simulator --debug integration_test/picker_test.dart
130+
xcodebuild test -workspace ios/Runner.xcworkspace -scheme Runner -destination "id=${{ steps.simulator.outputs.udid }}" \
131+
-only-testing:RunnerTests -parallel-testing-enabled NO -quiet

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,6 @@ Add `NSPhotoLibraryUsageDescription` to `Info.plist`.
8585
- iOS simulator: `xcrun simctl privacy <device> grant photos dev.noegnh.filmkitPickerExample`.
8686

8787
The tests add two samples to the library (`filmkit_picker_sample.jpg` and `.mp4`) once, and find them again on later runs.
88-
- CI (`.github/workflows/ci.yml`): format, analysis and Dart tests; Android build; the integration tests on an Android emulator and an iOS simulator.
88+
89+
On iOS simulators, `flutter test` often never sees the app start (flutter/flutter#181771). The CI runs the same tests through XCTest instead, with `example/ios/RunnerTests/RunnerTests.m`: `flutter build ios --config-only --simulator --debug integration_test/picker_test.dart`, then `xcodebuild test -workspace ios/Runner.xcworkspace -scheme Runner -destination 'platform=iOS Simulator,name=<device>' -only-testing:RunnerTests`.
90+
- CI (`.github/workflows/ci.yml`): format, analysis and Dart tests; Android build; the integration tests on an Android emulator and an iOS simulator (through XCTest).

‎example/integration_test/picker_test.dart‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ void main() {
6363
});
6464

6565
group('PhotoManagerLibrary', () {
66-
test('lists the "all" album first, newest first', () async {
66+
testWidgets('lists the "all" album first, newest first', (tester) async {
6767
final albums = await library.albums(PickerMediaType.all);
6868
expect(albums.first.isAll, isTrue);
6969
expect(albums.first.count, greaterThanOrEqualTo(2));
@@ -74,20 +74,20 @@ void main() {
7474
}
7575
});
7676

77-
test('filters photos and videos', () async {
77+
testWidgets('filters photos and videos', (tester) async {
7878
final photos = (await library.albums(PickerMediaType.photos)).first;
7979
final videos = (await library.albums(PickerMediaType.videos)).first;
8080
expect(await library.items(photos, page: 0, size: 500), isNot(contains(video)));
8181
expect(await library.items(videos, page: 0, size: 500), everyElement(predicate<MediaItem>((i) => i.isVideo)));
8282
});
8383

84-
test('gives displayed sizes and video durations', () {
84+
testWidgets('gives displayed sizes and video durations', (tester) async {
8585
expect((photo.width, photo.height, photo.isVideo), (300, 200, false));
8686
expect((video.width, video.height, video.isVideo), (640, 360, true));
8787
expect(video.duration.inSeconds, inInclusiveRange(5, 6));
8888
});
8989

90-
test('makes oriented thumbnails', () async {
90+
testWidgets('makes oriented thumbnails', (tester) async {
9191
Future<ui.Image> decode(Uint8List? bytes) async => (await (await ui.instantiateImageCodec(bytes!)).getNextFrame()).image;
9292
final fit = await decode(await library.thumbnail(photo, width: 150, height: 100));
9393
expect(fit.width / fit.height, closeTo(1.5, 0.05), reason: 'oriented, aspect kept');
@@ -98,7 +98,7 @@ void main() {
9898
expect(cell.height, greaterThanOrEqualTo(128));
9999
});
100100

101-
test('reads the files', () async {
101+
testWidgets('reads the files', (tester) async {
102102
final photoPath = await library.file(photo);
103103
final videoPath = await library.file(video);
104104
expect(File(photoPath!).lengthSync(), greaterThan(0));

‎example/ios/Runner.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
/* Begin PBXBuildFile section */
1010
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
11-
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.swift */; };
11+
331C808B294A63AB00263BE5 /* RunnerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 331C807B294A618700263BE5 /* RunnerTests.m */; };
1212
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
1313
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
1414
7884E8682EC3CC0700C636F2 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7884E8672EC3CC0400C636F2 /* SceneDelegate.swift */; };
@@ -44,7 +44,7 @@
4444
/* Begin PBXFileReference section */
4545
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
4646
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
47-
331C807B294A618700263BE5 /* RunnerTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RunnerTests.swift; sourceTree = "<group>"; };
47+
331C807B294A618700263BE5 /* RunnerTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RunnerTests.m; sourceTree = "<group>"; };
4848
331C8081294A63A400263BE5 /* RunnerTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = RunnerTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
4949
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
5050
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
@@ -76,7 +76,7 @@
7676
331C8082294A63A400263BE5 /* RunnerTests */ = {
7777
isa = PBXGroup;
7878
children = (
79-
331C807B294A618700263BE5 /* RunnerTests.swift */,
79+
331C807B294A618700263BE5 /* RunnerTests.m */,
8080
);
8181
path = RunnerTests;
8282
sourceTree = "<group>";
@@ -273,7 +273,7 @@
273273
isa = PBXSourcesBuildPhase;
274274
buildActionMask = 2147483647;
275275
files = (
276-
331C808B294A63AB00263BE5 /* RunnerTests.swift in Sources */,
276+
331C808B294A63AB00263BE5 /* RunnerTests.m in Sources */,
277277
);
278278
runOnlyForDeploymentPostprocessing = 0;
279279
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
@import XCTest;
2+
@import integration_test;
3+
4+
// Runs integration_test/picker_test.dart (the target of `flutter build ios --config-only`) as
5+
// XCTest cases: unlike `flutter test`, it doesn't depend on the tool finding the app's VM
6+
// service, which often fails on iOS simulators (flutter/flutter#181771).
7+
INTEGRATION_TEST_IOS_RUNNER(RunnerTests)

‎example/ios/RunnerTests/RunnerTests.swift‎

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

0 commit comments

Comments
 (0)