diff --git a/.github/workflows/test.yml b/.github/workflows/test_0.yml similarity index 96% rename from .github/workflows/test.yml rename to .github/workflows/test_0.yml index 432c5c40..bc511fbd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test_0.yml @@ -1,4 +1,4 @@ -name: Test +name: Test_0 on: push: @@ -55,7 +55,7 @@ jobs: - name: Test run: | - bundle exec fastlane test + bundle exec fastlane test_0 - name: Tests reports upload uses: actions/upload-artifact@v3 diff --git a/.github/workflows/test_1.yml b/.github/workflows/test_1.yml new file mode 100644 index 00000000..ffd23bdf --- /dev/null +++ b/.github/workflows/test_1.yml @@ -0,0 +1,65 @@ +name: Test_1 + +on: + push: + branches: + - main + - feature/* + pull_request: + workflow_dispatch: + +env: + DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer + +jobs: + test: + runs-on: macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Ruby & Bundle setup + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + bundler-cache: true + + - name: Cocoapods cache + uses: actions/cache@v3 + with: + path: Pods + key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} + restore-keys: | + ${{ runner.os }}-pods- + + - name: Cocoapods install + run: | + bundle exec fastlane run cocoapods + + - name: Setup Java 11 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + + - name: WireMock setup + run: | + curl https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-jre8-standalone/2.27.0/wiremock-jre8-standalone-2.27.0.jar -o wiremock.jar -s + bundle exec iostrust add ./wiremock/cert/wiremock.crt + java -jar wiremock.jar --https-port 9099 --root-dir wiremock --https-keystore wiremock/cert/wiremock.jks --keystore-password password --verbose --global-response-templating & + + - name: Format check + run: | + bundle exec fastlane format_check + + - name: Test + run: | + bundle exec fastlane test_1 + + - name: Tests reports upload + uses: actions/upload-artifact@v3 + if: failure() + with: + name: tests-reports + path: "fastlane/test_output" diff --git a/.github/workflows/test_2.yml b/.github/workflows/test_2.yml new file mode 100644 index 00000000..6d299d8a --- /dev/null +++ b/.github/workflows/test_2.yml @@ -0,0 +1,65 @@ +name: Test_2 + +on: + push: + branches: + - main + - feature/* + pull_request: + workflow_dispatch: + +env: + DEVELOPER_DIR: /Applications/Xcode_14.2.app/Contents/Developer + +jobs: + test: + runs-on: macos-latest + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Ruby & Bundle setup + uses: ruby/setup-ruby@v1 + with: + ruby-version: 2.6 + bundler-cache: true + + - name: Cocoapods cache + uses: actions/cache@v3 + with: + path: Pods + key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} + restore-keys: | + ${{ runner.os }}-pods- + + - name: Cocoapods install + run: | + bundle exec fastlane run cocoapods + + - name: Setup Java 11 + uses: actions/setup-java@v3 + with: + distribution: 'temurin' + java-version: '11' + + - name: WireMock setup + run: | + curl https://repo1.maven.org/maven2/com/github/tomakehurst/wiremock-jre8-standalone/2.27.0/wiremock-jre8-standalone-2.27.0.jar -o wiremock.jar -s + bundle exec iostrust add ./wiremock/cert/wiremock.crt + java -jar wiremock.jar --https-port 9099 --root-dir wiremock --https-keystore wiremock/cert/wiremock.jks --keystore-password password --verbose --global-response-templating & + + - name: Format check + run: | + bundle exec fastlane format_check + + - name: Test + run: | + bundle exec fastlane test_2 + + - name: Tests reports upload + uses: actions/upload-artifact@v3 + if: failure() + with: + name: tests-reports + path: "fastlane/test_output" diff --git a/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/project.pbxproj b/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/project.pbxproj index f0374aa5..5f92dbec 100644 --- a/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/project.pbxproj +++ b/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/project.pbxproj @@ -729,14 +729,7 @@ A82D7DF12A04FEAB001302A8 /* CRMRAIDUtils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CRMRAIDUtils.swift; sourceTree = ""; }; A82D7DF32A0A3ED4001302A8 /* MRAIDUtilsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MRAIDUtilsTests.swift; sourceTree = ""; }; A82D7E1D2A20B28E001302A8 /* CriteoPublisherSdkMC1.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC1.xctestplan; sourceTree = ""; }; - A82D7E1E2A20B28E001302A8 /* CriteoPublisherSdkMC9.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC9.xctestplan; sourceTree = ""; }; - A82D7E1F2A20B28E001302A8 /* CriteoPublisherSdkMC4.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC4.xctestplan; sourceTree = ""; }; - A82D7E202A20B28E001302A8 /* CriteoPublisherSdkMC3.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC3.xctestplan; sourceTree = ""; }; - A82D7E212A20B28E001302A8 /* CriteoPublisherSdkMC6.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC6.xctestplan; sourceTree = ""; }; - A82D7E222A20B28E001302A8 /* CriteoPublisherSdkMC8.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC8.xctestplan; sourceTree = ""; }; - A82D7E232A20B28E001302A8 /* CriteoPublisherSdkMC5.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC5.xctestplan; sourceTree = ""; }; A82D7E242A20B28E001302A8 /* CriteoPublisherSdkMC0.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC0.xctestplan; sourceTree = ""; }; - A82D7E252A20B28E001302A8 /* CriteoPublisherSdkMC7.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC7.xctestplan; sourceTree = ""; }; A82D7E262A20B28E001302A8 /* CriteoPublisherSdkMC2.xctestplan */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CriteoPublisherSdkMC2.xctestplan; sourceTree = ""; }; A83BB58929BAEB69002A63B6 /* ActionRepresentable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ActionRepresentable.swift; sourceTree = ""; }; A83BB58B29BAEBC9002A63B6 /* MRAIDLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MRAIDLog.swift; sourceTree = ""; }; @@ -1576,15 +1569,8 @@ A82D7E1C2A20B28E001302A8 /* TestPlans */ = { isa = PBXGroup; children = ( - A82D7E1D2A20B28E001302A8 /* CriteoPublisherSdkMC1.xctestplan */, - A82D7E1E2A20B28E001302A8 /* CriteoPublisherSdkMC9.xctestplan */, - A82D7E1F2A20B28E001302A8 /* CriteoPublisherSdkMC4.xctestplan */, - A82D7E202A20B28E001302A8 /* CriteoPublisherSdkMC3.xctestplan */, - A82D7E212A20B28E001302A8 /* CriteoPublisherSdkMC6.xctestplan */, - A82D7E222A20B28E001302A8 /* CriteoPublisherSdkMC8.xctestplan */, - A82D7E232A20B28E001302A8 /* CriteoPublisherSdkMC5.xctestplan */, A82D7E242A20B28E001302A8 /* CriteoPublisherSdkMC0.xctestplan */, - A82D7E252A20B28E001302A8 /* CriteoPublisherSdkMC7.xctestplan */, + A82D7E1D2A20B28E001302A8 /* CriteoPublisherSdkMC1.xctestplan */, A82D7E262A20B28E001302A8 /* CriteoPublisherSdkMC2.xctestplan */, ); path = TestPlans; diff --git a/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/xcshareddata/xcschemes/CriteoPublisherSdk.xcscheme b/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/xcshareddata/xcschemes/CriteoPublisherSdk.xcscheme index 89b66d87..7b67f03b 100644 --- a/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/xcshareddata/xcschemes/CriteoPublisherSdk.xcscheme +++ b/CriteoPublisherSdk/CriteoPublisherSdk.xcodeproj/xcshareddata/xcschemes/CriteoPublisherSdk.xcscheme @@ -38,33 +38,12 @@ - - - - - - - - - - - - - - @property(strong, nonatomic) Criteo *criteo; @property(strong, nonatomic) CR_IntegrationRegistry *integrationRegistry; @property(nonatomic, strong) id loggingMock; +@property(strong, nonatomic) CRBannerView *bannerView; @end @implementation CRBannerViewTests @@ -84,6 +85,7 @@ - (void)tearDown { // Not sure why this is needed but without this testWithRendering is failing. // Maybe this come from OCMock not handling properly partial mock ??? self.criteo = nil; + self.bannerView = nil; [self.loggingMock stopMocking]; } @@ -105,10 +107,10 @@ - (void)testBannerSuccess { [webViewLoadedExpectation fulfill]; }); - CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView]; + _bannerView = [self bannerViewWithWebView:mockWebView]; OCMVerify([self.loggingMock logMessage:[self checkMessageContainsString:@"Initializing"]]); - [bannerView loadAdWithContext:self.contextData]; + [_bannerView loadAdWithContext:self.contextData]; OCMVerify([self.loggingMock logMessage:[self checkMessageContainsString:@"Loading"]]); OCMVerify([self.loggingMock logMessage:[self checkMessageContainsString:@"Received"]]); @@ -122,10 +124,9 @@ - (void)testBannerSuccess { - (void)testWebViewAddedToViewHierarchy { MockWKWebView *mockWebView = [MockWKWebView new]; + _bannerView = [self bannerViewWithWebView:mockWebView addWebView:YES]; - CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView addWebView:YES]; - - XCTAssertEqual(mockWebView, bannerView.subviews[0]); + XCTAssertEqual(mockWebView, _bannerView.subviews[0]); } - (void)testWithRendering { @@ -134,9 +135,9 @@ - (void)testWithRendering { CR_CdbBid *bid = [self cdbBidWithDisplayUrl:@"-"]; [self mockCriteoWithAdUnit:self.expectedCacheAdUnit respondBid:bid]; - CRBannerView *bannerView = [self bannerViewWithWebView:realWebView]; + _bannerView = [self bannerViewWithWebView:realWebView]; realWebView.navigationDelegate = self; - [bannerView loadAdWithContext:self.contextData]; + [_bannerView loadAdWithContext:self.contextData]; XCTestExpectation __block *marginExpectation = [self expectationWithDescription:@"WebView body has 0px margin"]; @@ -180,8 +181,8 @@ - (void)testBannerFail { WKWebView *realWebView = [WKWebView new]; [self mockCriteoWithAdUnit:self.expectedCacheAdUnit respondBid:nil]; - CRBannerView *bannerView = [self bannerViewWithWebView:realWebView]; - [bannerView loadAdWithContext:self.contextData]; + _bannerView = [self bannerViewWithWebView:realWebView]; + [_bannerView loadAdWithContext:self.contextData]; OCMVerify([self.loggingMock logMessage:[OCMArg checkWithBlock:^BOOL(CR_LogMessage *logMessage) { return [logMessage.tag isEqualToString:@"BannerView"] && [logMessage.message containsString:@"Failed"] && @@ -199,11 +200,11 @@ - (void)testAllowNavigationActionPolicyForWebView { /* Allow navigation Types other than Links from Mainframes in WebView. eg: Clicking images inside tag generates WKNavigationTypeOther */ - CRBannerView *bannerView = [self bannerViewWithWebView:nil]; + _bannerView = [self bannerViewWithWebView:nil]; WKNavigationAction *mockNavigationAction = OCMStrictClassMock([WKNavigationAction class]); OCMStub(mockNavigationAction.navigationType).andReturn(WKNavigationTypeOther); - [bannerView webView:nil + [_bannerView webView:nil decidePolicyForNavigationAction:mockNavigationAction decisionHandler:^(WKNavigationActionPolicy actionPolicy) { XCTAssertEqual(actionPolicy, WKNavigationActionPolicyAllow); @@ -216,7 +217,7 @@ - (void)testAllowNavigationActionPolicyForWebView { OCMStub([mockFrame isMainFrame]).andReturn(YES); NSURLRequest *request = [[NSURLRequest alloc] init]; OCMStub(mockNavigationAction.request).andReturn(request); - [bannerView webView:nil + [_bannerView webView:nil decidePolicyForNavigationAction:mockNavigationAction decisionHandler:^(WKNavigationActionPolicy actionPolicy) { XCTAssertEqual(actionPolicy, WKNavigationActionPolicyAllow); @@ -237,8 +238,8 @@ - (void)testCancelNavigationActionPolicyForWebView { XCTestExpectation *openInBrowserExpectation = [self expectationWithDescription:@"URL opened in browser expectation"]; - CRBannerView *bannerView = [self bannerViewWithWebView:nil]; - [bannerView webView:nil + _bannerView = [self bannerViewWithWebView:nil]; + [_bannerView webView:nil decidePolicyForNavigationAction:mockNavigationAction decisionHandler:^(WKNavigationActionPolicy actionPolicy) { XCTAssertEqual(actionPolicy, WKNavigationActionPolicyCancel); @@ -270,8 +271,8 @@ - (void)testCreateWebViewWithConfiguration { XCTestExpectation *openInBrowserExpectation = [self expectationWithDescription:@"URL opened in browser expectation"]; - CRBannerView *bannerView = [self bannerViewWithWebView:realWebView]; - [bannerView webView:realWebView + _bannerView = [self bannerViewWithWebView:realWebView]; + [_bannerView webView:realWebView createWebViewWithConfiguration:nil forNavigationAction:mockNavigationAction windowFeatures:nil]; @@ -297,8 +298,8 @@ - (void)testDisplayAdWithDataSuccess { [webViewLoadedExpectation fulfill]; }); - CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView]; - [bannerView loadAdWithDisplayData:TEST_DISPLAY_URL]; + _bannerView = [self bannerViewWithWebView:mockWebView]; + [_bannerView loadAdWithDisplayData:TEST_DISPLAY_URL]; [self cr_waitForExpectations:@[ webViewLoadedExpectation ]]; OCMVerifyAll(mockWebView); @@ -322,14 +323,13 @@ - (void)testLoadingWithBidSuccess { CR_CdbBid *cdbBid = [self cdbBidWithDisplayUrl:TEST_DISPLAY_URL]; CRBid *bid = [[CRBid alloc] initWithCdbBid:cdbBid adUnit:self.adUnit]; - CRBannerView *bannerView = - [[CRBannerView alloc] initWithFrame:CGRectMake(13.0f, 17.0f, 47.0f, 57.0f) - criteo:self.criteo - webView:mockWebView - addWebView:NO - adUnit:nil - urlOpener:self.urlOpener]; - [bannerView loadAdWithBid:bid]; + _bannerView = [[CRBannerView alloc] initWithFrame:CGRectMake(13.0f, 17.0f, 47.0f, 57.0f) + criteo:self.criteo + webView:mockWebView + addWebView:NO + adUnit:nil + urlOpener:self.urlOpener]; + [_bannerView loadAdWithBid:bid]; [self cr_waitForExpectations:@[ webViewLoadedExpectation ]]; OCMVerifyAll(mockWebView); @@ -355,8 +355,8 @@ - (void)testTemplatingFromConfig { CR_CdbBid *cdbBid = [self cdbBidWithDisplayUrl:displayURL]; CRBid *bid = [[CRBid alloc] initWithCdbBid:cdbBid adUnit:self.adUnit]; - CRBannerView *bannerView = [self bannerViewWithWebView:mockWebView]; - [bannerView loadAdWithBid:bid]; + _bannerView = [self bannerViewWithWebView:mockWebView]; + [_bannerView loadAdWithBid:bid]; [self cr_waitForExpectations:@[ webViewLoadedExpectation ]]; OCMVerifyAll(mockWebView); @@ -378,13 +378,13 @@ - (CRBannerView *)testbannerViewWithMRAID:(BOOL)mraidFlag { } - (void)testMRAIDOffOnConfig { - CRBannerView *bannerView = [self testbannerViewWithMRAID:NO]; - XCTAssertNil(bannerView.mraidHandler); + _bannerView = [self testbannerViewWithMRAID:NO]; + XCTAssertNil(_bannerView.mraidHandler); } - (void)testMRAIDActiveOnConfig { - CRBannerView *bannerView = [self testbannerViewWithMRAID:YES]; - XCTAssertNotNil(bannerView.mraidHandler); + _bannerView = [self testbannerViewWithMRAID:YES]; + XCTAssertNotNil(_bannerView.mraidHandler); } #pragma mark - Private diff --git a/fastlane/Fastfile b/fastlane/Fastfile index 69e58619..8be93201 100644 --- a/fastlane/Fastfile +++ b/fastlane/Fastfile @@ -38,6 +38,53 @@ platform :ios do pod_lib_lint end + desc %(Run tests: Run Unit & Functional tests with retries) + lane :test_0 do + scan(scheme: "CriteoAdViewer") + scan(scheme: "CriteoGoogleAdapter") + run_tests(workspace: "CriteoPublisherSdk.xcworkspace", + devices: ["iPhone 14"], + scheme: "CriteoPublisherSdk", + testplan: "CriteoPublisherSdkMC0", + app_identifier: "CriteoPublisherSdk", + number_of_retries: 5, + concurrent_workers: 2, + reset_simulator: true, + clean: true, + reinstall_app: true + ) + end + + desc %(Run tests: Run Unit & Functional tests with retries) + lane :test_1 do + run_tests(workspace: "CriteoPublisherSdk.xcworkspace", + devices: ["iPhone 14"], + scheme: "CriteoPublisherSdk", + testplan: "CriteoPublisherSdkMC1", + app_identifier: "CriteoPublisherSdk", + number_of_retries: 5, + concurrent_workers: 2, + reset_simulator: true, + clean: true, + reinstall_app: true + ) + end + + desc %(Run tests: Run Unit & Functional tests with retries) + lane :test_2 do + run_tests(workspace: "CriteoPublisherSdk.xcworkspace", + devices: ["iPhone 14"], + scheme: "CriteoPublisherSdk", + testplan: "CriteoPublisherSdkMC2", + app_identifier: "CriteoPublisherSdk", + number_of_retries: 5, + concurrent_workers: 2, + reset_simulator: true, + clean: true, + reinstall_app: true + ) + end + desc %(Check code format) lane :format_check do run_clang_format( diff --git a/fastlane/README.md b/fastlane/README.md index 06d0507a..6b923744 100644 --- a/fastlane/README.md +++ b/fastlane/README.md @@ -21,6 +21,21 @@ or alternatively using `brew install fastlane` fastlane ios test ``` Run tests: Run Unit & Functional tests with retries +### ios test_0 +``` +fastlane ios test_0 +``` +Run tests: Run Unit & Functional tests with retries +### ios test_1 +``` +fastlane ios test_1 +``` +Run tests: Run Unit & Functional tests with retries +### ios test_2 +``` +fastlane ios test_2 +``` +Run tests: Run Unit & Functional tests with retries ### ios format_check ``` fastlane ios format_check