Skip to content

Commit

Permalink
Move unit tests to example/RunnerTests (#802)
Browse files Browse the repository at this point in the history
* Move unit tests to example/is/RunnerTests
* Remove melos from install-tools
* Upload iOS test result to github when tests fail
  • Loading branch information
jjliu15 committed Mar 22, 2023
1 parent 5a8e475 commit 2137b05
Show file tree
Hide file tree
Showing 27 changed files with 306 additions and 313 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/google_mobile_ads.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ on:
env:
GOOGLEMOBILEADS_PLUGIN_SCOPE: "*google_mobile_ads*"
GOOGLEMOBILEADS_PLUGIN_SCOPE_EXAMPLE: "*google_mobile_ads_example*"

jobs:
android:
runs-on: macos-latest
Expand Down Expand Up @@ -66,8 +65,15 @@ jobs:
- name: "Unit Tests"
run: |
cd packages/google_mobile_ads/example/ios
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
flutter clean
flutter pub get
pod install
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
- uses: actions/upload-artifact@v3
if: failure()
with:
name: iOSTestResults
path: packages/google_mobile_ads/example/ios/TestResults.xcresult
flutter:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/scripts/install-tools.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
# Copyright 2021 Google LLC
# Copyright 2023 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

flutter pub global activate melos
echo "$HOME/.pub-cache/bin" >> $GITHUB_PATH
echo "$GITHUB_WORKSPACE/_flutter/.pub-cache/bin" >> $GITHUB_PATH
echo "$GITHUB_WORKSPACE/_flutter/bin/cache/dart-sdk/bin" >> $GITHUB_PATH
13 changes: 7 additions & 6 deletions packages/google_mobile_ads/example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))

target 'RunnerTests' do
inherit! :search_paths

# Matches test_spec dependency.
pod 'OCMock', '3.6'
end
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end

# Add test dependency matching google_mobile_ads.podspec.
target 'google_mobile_ads_exampleTests' do
pod 'OCMock','3.6'
end
542 changes: 258 additions & 284 deletions packages/google_mobile_ads/example/ios/Runner.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions packages/google_mobile_ads/example/ios/Runner/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@
<true/>
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
Expand Up @@ -195,20 +195,20 @@ - (void)testAdInstanceManagerOnAppEvent {
adId:@1
nativeAdOptions:nil
nativeTemplateStyle:nil];
FlutterMethodChannel *mockMethodChannel =
OCMClassMock([FlutterMethodChannel class]);
[_manager setValue:mockMethodChannel forKey:@"_channel"];
[_manager loadAd:ad];

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

NSData *data = [_methodCodec
encodeMethodCall:[FlutterMethodCall
methodCallWithMethodName:@"onAdEvent"
arguments:@{
@"adId" : @1,
@"eventName" : @"onAppEvent",
@"name" : @"color",
@"data" : @"red"
}]];
OCMVerify([_mockMessenger sendOnChannel:channel message:data]);
NSDictionary *arguments = @{
@"adId" : @1,
@"eventName" : @"onAppEvent",
@"name" : @"color",
@"data" : @"red"
};
OCMVerify([mockMethodChannel invokeMethod:@"onAdEvent" arguments:arguments]);
}

- (void)testAdInstanceManagerOnNativeAdEvents {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,11 @@ - (void)testLoadShowRewardedAd:(FLTAdRequest *)request
XCTAssertEqual(reward.type, @"type");
return true;
}]]);

// Explicitly stop mocking. There is an issue when running tests on Github
// actions where the mock does not get deallocated properly, so without this
// other test cases will fail.
[rewardedClassMock stopMocking];
}

- (void)testFailedToLoadGADRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ - (void)testLoadShowRewardedInterstitialAd:(FLTAdRequest *)request
XCTAssertEqual(reward.type, @"type");
return true;
}]]);
// Call stopMocking. There's a bug where mocks are not stopping automatically
// after the test finishes.
[rewardedInterstitialClassMock stopMocking];
}

- (void)testFailedToLoadGADRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,22 @@ @interface FLTNativeTemplateTypeTest : XCTestCase
@implementation FLTNativeTemplateTypeTest

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

templateType = [[FLTNativeTemplateType alloc] initWithInt:1];
XCTAssertEqual(templateType.xibName, @"GADTMediumTemplateView");
FLTNativeTemplateType *templateTypeMedium =
[[FLTNativeTemplateType alloc] initWithInt:1];
XCTAssertEqualObjects(templateTypeMedium.xibName, @"GADTMediumTemplateView");

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

templateType = [[FLTNativeTemplateType alloc] initWithInt:2];
XCTAssertEqual(templateType.xibName, @"GADTMediumTemplateView");
FLTNativeTemplateType *templateType =
[[FLTNativeTemplateType alloc] initWithInt:2];
XCTAssertEqualObjects(templateType.xibName, @"GADTMediumTemplateView");
}

@end

0 comments on commit 2137b05

Please sign in to comment.