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

Update hosted tests for Swift Testing #110

Merged
merged 1 commit into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion testing/hosted_test/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import UIKit

@UIApplicationMain
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?

Expand Down
15 changes: 14 additions & 1 deletion testing/hosted_test/HostedTests.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import XCTest
import Testing

class Tests: XCTestCase {
class XCTestDemo: XCTestCase {
func testFailed() throws {
XCTAssert(false)
}
Expand All @@ -12,3 +13,15 @@ class Tests: XCTestCase {
XCTAssert(true)
}
}

@Suite struct SwiftTestingDemo {
@Test func failed() {
#expect(Bool(false))
}

@Test func window() {
// Accessing the host app
print(UIApplication.shared.windows)
#expect(Bool(true))
}
}
17 changes: 12 additions & 5 deletions testing/hosted_test/build_and_test.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/bin/zsh
# This script was tested on Xcode 14.0
# This script was tested on Xcode 16.0

TARGET="x86_64-apple-ios14.0-simulator"
set -e

TARGET="arm64-apple-ios16.0-simulator"
SDKROOT=$(xcrun --show-sdk-path --sdk iphonesimulator)
PLATFORM_DIR="$(xcode-select -p)/Platforms/iPhoneSimulator.platform"
TOOLCHAIN_DIR="$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain"
Expand All @@ -12,11 +14,16 @@ mkdir -p build/HostApp.app

# Building the host app
xcrun swiftc AppDelegate.swift ViewController.swift \
-sdk "$SDKROOT" -target "$TARGET" \
-sdk "$SDKROOT" \
-target "$TARGET" \
-emit-executable \
-Xlinker -rpath -Xlinker @executable_path/Frameworks \
-o "build/HostApp.app/HostApp"

cp App-Info.plist build/HostApp.app/Info.plist
ditto App-Info.plist build/HostApp.app/Info.plist

# For Swift Testing, Testing.framework needs to be bundled with the host app
ditto "$PLATFORM_DIR/Developer/Library/Frameworks/Testing.framework" build/HostApp.app/Frameworks/Testing.framework

# Building the test
mkdir -p build/HostApp.app/PlugIns/HostedTests.xctest
Expand All @@ -38,7 +45,7 @@ xcrun ld -bundle -o build/HostApp.app/PlugIns/HostedTests.xctest/HostedTests bui

# Install the app
xcrun simctl shutdown all
xcrun simctl boot "iPhone 14 Pro"
xcrun simctl boot "iPhone 16"
xcrun simctl install booted "$(realpath build/HostApp.app)"

# Launch the app and run the tests
Expand Down
Loading