Skip to content

Commit

Permalink
Update hosted test for Swift Testing (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
qyang-nj authored Oct 8, 2024
1 parent b0fec03 commit 7579493
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
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

0 comments on commit 7579493

Please sign in to comment.