Skip to content

Commit 2137b05

Browse files
authored
Move unit tests to example/RunnerTests (#802)
* Move unit tests to example/is/RunnerTests * Remove melos from install-tools * Upload iOS test result to github when tests fail
1 parent 5a8e475 commit 2137b05

27 files changed

+306
-313
lines changed

.github/workflows/google_mobile_ads.yaml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ on:
2828
env:
2929
GOOGLEMOBILEADS_PLUGIN_SCOPE: "*google_mobile_ads*"
3030
GOOGLEMOBILEADS_PLUGIN_SCOPE_EXAMPLE: "*google_mobile_ads_example*"
31-
3231
jobs:
3332
android:
3433
runs-on: macos-latest
@@ -66,8 +65,15 @@ jobs:
6665
- name: "Unit Tests"
6766
run: |
6867
cd packages/google_mobile_ads/example/ios
69-
xcodebuild -configuration Debug VERBOSE_SCRIPT_LOGGING=YES -workspace Runner.xcworkspace -scheme Runner -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=16.2' test
70-
68+
flutter clean
69+
flutter pub get
70+
pod install
71+
xcodebuild -configuration Debug -resultBundlePath TestResults VERBOSE_SCRIPT_LOGGING=YES -workspace Runner.xcworkspace -scheme Runner -sdk iphonesimulator -destination 'platform=iOS Simulator,name=iPhone 14 Pro,OS=16.2' test
72+
- uses: actions/upload-artifact@v3
73+
if: failure()
74+
with:
75+
name: iOSTestResults
76+
path: packages/google_mobile_ads/example/ios/TestResults.xcresult
7177
flutter:
7278
runs-on: ubuntu-latest
7379
if: github.event_name == 'pull_request'

.github/workflows/scripts/install-tools.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2021 Google LLC
2+
# Copyright 2023 Google LLC
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.
@@ -13,7 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
flutter pub global activate melos
1716
echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
1817
echo "$GITHUB_WORKSPACE/_flutter/.pub-cache/bin" >> $GITHUB_PATH
1918
echo "$GITHUB_WORKSPACE/_flutter/bin/cache/dart-sdk/bin" >> $GITHUB_PATH

packages/google_mobile_ads/example/ios/Podfile

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,17 +30,18 @@ flutter_ios_podfile_setup
3030
target 'Runner' do
3131
use_frameworks!
3232
use_modular_headers!
33-
3433
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
34+
35+
target 'RunnerTests' do
36+
inherit! :search_paths
37+
38+
# Matches test_spec dependency.
39+
pod 'OCMock', '3.6'
40+
end
3541
end
3642

3743
post_install do |installer|
3844
installer.pods_project.targets.each do |target|
3945
flutter_additional_ios_build_settings(target)
4046
end
4147
end
42-
43-
# Add test dependency matching google_mobile_ads.podspec.
44-
target 'google_mobile_ads_exampleTests' do
45-
pod 'OCMock','3.6'
46-
end

packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 258 additions & 284 deletions
Large diffs are not rendered by default.

packages/google_mobile_ads/example/ios/Runner/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,7 @@
5858
<true/>
5959
<key>CADisableMinimumFrameDurationOnPhone</key>
6060
<true/>
61+
<key>UIApplicationSupportsIndirectInputEvents</key>
62+
<true/>
6163
</dict>
6264
</plist>

packages/google_mobile_ads/ios/Tests/FLTGoogleMobileAdsTest.m renamed to packages/google_mobile_ads/example/ios/RunnerTests/FLTGoogleMobileAdsTest.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,20 +195,20 @@ - (void)testAdInstanceManagerOnAppEvent {
195195
adId:@1
196196
nativeAdOptions:nil
197197
nativeTemplateStyle:nil];
198+
FlutterMethodChannel *mockMethodChannel =
199+
OCMClassMock([FlutterMethodChannel class]);
200+
[_manager setValue:mockMethodChannel forKey:@"_channel"];
198201
[_manager loadAd:ad];
199202

200203
[_manager onAppEvent:ad name:@"color" data:@"red"];
201204

202-
NSData *data = [_methodCodec
203-
encodeMethodCall:[FlutterMethodCall
204-
methodCallWithMethodName:@"onAdEvent"
205-
arguments:@{
206-
@"adId" : @1,
207-
@"eventName" : @"onAppEvent",
208-
@"name" : @"color",
209-
@"data" : @"red"
210-
}]];
211-
OCMVerify([_mockMessenger sendOnChannel:channel message:data]);
205+
NSDictionary *arguments = @{
206+
@"adId" : @1,
207+
@"eventName" : @"onAppEvent",
208+
@"name" : @"color",
209+
@"data" : @"red"
210+
};
211+
OCMVerify([mockMethodChannel invokeMethod:@"onAdEvent" arguments:arguments]);
212212
}
213213

214214
- (void)testAdInstanceManagerOnNativeAdEvents {

packages/google_mobile_ads/ios/Tests/FLTRewardedAdTest.m renamed to packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedAdTest.m

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
191191
XCTAssertEqual(reward.type, @"type");
192192
return true;
193193
}]]);
194+
195+
// Explicitly stop mocking. There is an issue when running tests on Github
196+
// actions where the mock does not get deallocated properly, so without this
197+
// other test cases will fail.
198+
[rewardedClassMock stopMocking];
194199
}
195200

196201
- (void)testFailedToLoadGADRequest {

packages/google_mobile_ads/ios/Tests/FLTRewardedInterstitialAdTest.m renamed to packages/google_mobile_ads/example/ios/RunnerTests/FLTRewardedInterstitialAdTest.m

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,9 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request
179179
XCTAssertEqual(reward.type, @"type");
180180
return true;
181181
}]]);
182+
// Call stopMocking. There's a bug where mocks are not stopping automatically
183+
// after the test finishes.
184+
[rewardedInterstitialClassMock stopMocking];
182185
}
183186

184187
- (void)testFailedToLoadGADRequest {

packages/google_mobile_ads/ios/Tests/NativeTemplates/FLTNativeTemplateTypeTest.m renamed to packages/google_mobile_ads/example/ios/RunnerTests/NativeTemplates/FLTNativeTemplateTypeTest.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,22 @@ @interface FLTNativeTemplateTypeTest : XCTestCase
2121
@implementation FLTNativeTemplateTypeTest
2222

2323
- (void)testXibName {
24-
FLTNativeTemplateType *templateType =
24+
FLTNativeTemplateType *templateTypeSmall =
2525
[[FLTNativeTemplateType alloc] initWithInt:0];
26-
XCTAssertEqual(templateType.xibName, @"GADTSmallTemplateView");
26+
XCTAssertEqualObjects(templateTypeSmall.xibName, @"GADTSmallTemplateView");
2727

28-
templateType = [[FLTNativeTemplateType alloc] initWithInt:1];
29-
XCTAssertEqual(templateType.xibName, @"GADTMediumTemplateView");
28+
FLTNativeTemplateType *templateTypeMedium =
29+
[[FLTNativeTemplateType alloc] initWithInt:1];
30+
XCTAssertEqualObjects(templateTypeMedium.xibName, @"GADTMediumTemplateView");
3031

3132
// Unknown templates default to medium
32-
templateType = [[FLTNativeTemplateType alloc] initWithInt:-1];
33-
XCTAssertEqual(templateType.xibName, @"GADTMediumTemplateView");
33+
FLTNativeTemplateType *templateTypeUnknown =
34+
[[FLTNativeTemplateType alloc] initWithInt:-1];
35+
XCTAssertEqualObjects(templateTypeUnknown.xibName, @"GADTMediumTemplateView");
3436

35-
templateType = [[FLTNativeTemplateType alloc] initWithInt:2];
36-
XCTAssertEqual(templateType.xibName, @"GADTMediumTemplateView");
37+
FLTNativeTemplateType *templateType =
38+
[[FLTNativeTemplateType alloc] initWithInt:2];
39+
XCTAssertEqualObjects(templateType.xibName, @"GADTMediumTemplateView");
3740
}
3841

3942
@end

0 commit comments

Comments
 (0)