Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StoreKitUnitTests: compile on iOS 11.0+ #1904

Merged
merged 2 commits into from
Sep 15, 2022
Merged

StoreKitUnitTests: compile on iOS 11.0+ #1904

merged 2 commits into from
Sep 15, 2022

Conversation

NachoSoto
Copy link
Contributor

The entire target had a deployment target of iOS 14.0 because SKTestSession requires it. However, not all tests in that target use StoreKitConfigTestCase, and those weren't running before iOS 14.0.

To fix this, I've removed the deployment target overrides from all targets (expect for integration tests, those have a higher one for simplicity), and instead defined them only once at the project level, so all targets inherit that automatically.

StoreKitConfigTestCase will skip the test automatically if the iOS is below 14.0, but the other tests will now run on iOS 12 and 13.

The entire target had a deployment target of iOS 14.0 because `SKTestSession` requires it. However, not all tests in that target use `StoreKitConfigTestCase`, and those weren't running before iOS 14.0.

To fix this, I've removed the deployment target overrides from all targets (expect for integration tests, those have a higher one for simplicity), and instead defined them only once at the *project level*, so all targets inherit that automatically.

`StoreKitConfigTestCase` will skip the test automatically if the iOS is below 14.0, but the other tests will now run on iOS 12 and 13.
@NachoSoto NachoSoto added the test label Sep 13, 2022
@NachoSoto NachoSoto requested review from aboedo and a team September 13, 2022 00:49
Comment on lines +3187 to +3199
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
MACOSX_DEPLOYMENT_TARGET = 10.13;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SUPPORTS_MACCATALYST = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_STRICT_CONCURRENCY = targeted;
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES;
TVOS_DEPLOYMENT_TARGET = 11.0;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
WATCHOS_DEPLOYMENT_TARGET = 6.2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ These are now at the project level instead of duplicated in each target.

@@ -69,44 +70,44 @@ extension StoreKitConfigTestCase {
) async {
self.testSession.storefront = new

if #available(iOS 15.0, tvOS 15.0, macOS 12.0, watchOS 8.0, *) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this isn't necessary, but let's see if tests pass without it.


import UIKit

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This wasn't needed in the host app (and it's iOS 14.0+ only, so I just removed it).

Copy link
Contributor

@tonidero tonidero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes sense to me

@@ -16,7 +16,9 @@ import Nimble
import StoreKitTest
import XCTest

// swiftlint:disable:next type_name
// swiftlint:disable type_name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick. This will disable the rule for the whole file... Should we reenable at the end of the class? So if any extensions or anything get added later on, this doesn't get applied automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file only has one class (like most test classes) so I think that's unnecessary. Extensions are common to be added at the bottom, but they don't have "type names" so this wouldn't apply.

testSession.clearTransactions()
try super.setUpWithError()

try AvailabilityChecks.iOS14APIAvailableOrSkipTest()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a question, can this still be called before iOS 14 with the @available annotation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can. The annotation is only for compilation, but XCTest is not very smart and runs the tests anyway. That's why we have AvailabilityChecks.

@NachoSoto NachoSoto merged commit a9874f8 into main Sep 15, 2022
@NachoSoto NachoSoto deleted the unit-tests-ios-14 branch September 15, 2022 17:08
@@ -574,10 +574,8 @@ workflows:
xcode_version: '13.4.1'
- run-test-ios-13:
xcode_version: '13.4.1'
<<: *release-branches-and-main
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops I forgot to remove this. Re-added in #1909

NachoSoto pushed a commit that referenced this pull request Sep 23, 2022
**This is an automatic release.**

### Bugfixes
* `Purchases.beginRefundRequest`: ensured errors are `PublicError`
(#1913) via NachoSoto (@NachoSoto)
* `PurchaseTesterSwiftUI`: fixed macOS target (#1915) via NachoSoto
(@NachoSoto)
### Other Changes
* `SnapshotTesting`: require version 1.9.0 to keep supporting iOS 12/13
tests (#1931) via NachoSoto (@NachoSoto)
* Fixed `tvOS` tests (#1928) via NachoSoto (@NachoSoto)
* `pre-commit` hook: also verify leftover API keys in `PurchaseTester`
(#1914) via NachoSoto (@NachoSoto)
* `CircleCI`: changed iOS 12/13 to use Xcode 13 (#1918) via NachoSoto
(@NachoSoto)
* `PurchaseTesterSwiftUI`: removed unnecessary `UIApplicationDelegate`
(#1916) via NachoSoto (@NachoSoto)
* `CircleCI`: changed all jobs to use Xcode 14 (#1909) via NachoSoto
(@NachoSoto)
* `Atomic`: added unit test to verify `value`'s setter (#1905) via
NachoSoto (@NachoSoto)
* `spm build` CI job: changed to release build (#1903) via NachoSoto
(@NachoSoto)
* `StoreKitUnitTests`: compile on iOS 11.0+ (#1904) via NachoSoto
(@NachoSoto)
* `Purchases`: only expose testing data on `DEBUG` (#1902) via NachoSoto
(@NachoSoto)
* `Integration Tests`: added test to verify re-subscription behavior
(#1898) via NachoSoto (@NachoSoto)
* `IntegrationTests`: simplified `testExpireSubscription` to fix flaky
test (#1899) via NachoSoto (@NachoSoto)
* `Integration Tests`: actually verify that entitlement is active
(#1880) via NachoSoto (@NachoSoto)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants