From d3891ef217a4c2b0783c50c0ae54d01d37b2814f Mon Sep 17 00:00:00 2001 From: Qing Yang Date: Tue, 8 Oct 2024 11:48:43 -0700 Subject: [PATCH] move around --- README.md | 2 +- articles/iOSTesting.md | 44 ++++++++++++++++++++ {xctest => testing/xctest}/README.md | 2 +- {xctest => testing/xctest}/build_and_test.sh | 0 {xctest => testing/xctest}/test.swift | 0 5 files changed, 46 insertions(+), 2 deletions(-) rename {xctest => testing/xctest}/README.md (99%) rename {xctest => testing/xctest}/build_and_test.sh (100%) rename {xctest => testing/xctest}/test.swift (100%) diff --git a/README.md b/README.md index 3ea29b6..d5bf5b1 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ This repo is mostly my study notes about low level iOS. * [Behind the scenes: iOS Testing](./articles/iOSTesting.md) * [Behind the scenes: Code Coverage](./articles/CodeCoverage.md) * [Code Coverage on Test Crash](./articles/CodeCoverageOnTestCrash.md) - * [Archived] [XCTest](./xctest) + * [Archived] [XCTest](./testing/xctest) * Xcode * [Behind the scenes: SwiftUI Previews](./articles/SwiftUIPreview.md) * [Xcode.app Directory Structure](./articles/XcodeDirectoryStructure.md) diff --git a/articles/iOSTesting.md b/articles/iOSTesting.md index 80955b7..08c5d98 100644 --- a/articles/iOSTesting.md +++ b/articles/iOSTesting.md @@ -1,4 +1,7 @@ # Behind the scenes: iOS Testing + +(Updated on 10/8/2024) + This article uncovers what happens behind the scenes when building and running iOS tests. It explains what "xctest" can mean and three kinds of comment tests. To simplify the complexities, here we just talk about tests on iOS simulator. Other platforms are very similar. ## XCTest @@ -57,3 +60,44 @@ UI tests let us test our app like the end user. It can mimic the user behaviors, A more common scenario is to use `xcodebuild test-without-build` to run `.xctest`. [Here](../testing/xcodebuild/run_test.py) is a script to show how this works. ## Swift Testing +In Xcode 16, Apple introduced a testing framework called [Swift Testing](https://developer.apple.com/documentation/testing/). From the building perspective, Swift Testing is fully compatible with XCTest. We can write both Swift Testing and XCTest cases within the same module, or even in the same file. The build output for Swift Testing remains a .xctest bundle, with a few key differences outlined below. + +| |Swift Testing | XCTest | Notes | +|-------------|--------------| -------| ------- | +|Build product|.xctest bundle|.xctest bundle| | +|Framework |Testing.framework|XCTest.framework|| +|Compiling |-plugin-path $TOOL_CHAIN/usr/lib/swift/host/plugins/testing| | In a small sample code, this plugin doesn’t seem to have any effect. +|Linking |-lXCTestSwiftSupport||Without this linker flag, linking can succeed but no tests can be found at runtime. + + +The approach for running Swift tests remains the same as with XCTest. However, the output format of Swift Testing has changed, which can cause issues with tools that parse the results. For example, [xcbeautify is affected by this](https://github.com/cpisciotta/xcbeautify/issues/313). + +
+ Output from XCTest + +Test Suite 'All tests' started at 2024-10-08 10:33:04.291. +Test Suite 'Test.xctest' started at 2024-10-08 10:33:04.292. +Test Suite 'XCTestDemo' started at 2024-10-08 10:33:04.292. +Test Case '-[Test.XCTestDemo testMathOperations]' started. +Test Case '-[Test.XCTestDemo testMathOperations]' passed (0.000 seconds). +Test Suite 'XCTestDemo' passed at 2024-10-08 10:33:04.293. + Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds +Test Suite 'Test.xctest' passed at 2024-10-08 10:33:04.293. + Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.000) seconds +Test Suite 'All tests' passed at 2024-10-08 10:33:04.293. + Executed 1 test, with 0 failures (0 unexpected) in 0.000 (0.002) seconds +
+ +
+ Output from Swift Testing + +◇ Test run started. +↳ Testing Library Version: 94 (arm64-apple-ios13.0-simulator) +◇ Suite SwiftTestingDemo started. +◇ Test verifyMathOperations() started. +✔ Test verifyMathOperations() passed after 0.001 seconds. +✔ Suite SwiftTestingDemo passed after 0.001 seconds. +✔ Test run with 1 test passed after 0.001 seconds. + +
+ diff --git a/xctest/README.md b/testing/xctest/README.md similarity index 99% rename from xctest/README.md rename to testing/xctest/README.md index 3de49a4..e67bce3 100644 --- a/xctest/README.md +++ b/testing/xctest/README.md @@ -1,7 +1,7 @@ # XCTest > [!WARNING] -> This note is deprecated. See [Behind the scenes: iOS Testing](../articles/iOSTesting.md) +> This note is deprecated. See [Behind the scenes: iOS Testing](../../articles/iOSTesting.md) The word "xctest" is extensively used in the realm of iOS testing, the test bundle (`.xctest`), the test framework (`XCTest.framework`), and the test runner (`xctest`). This article along with a sample will dive into some details about iOS testing. diff --git a/xctest/build_and_test.sh b/testing/xctest/build_and_test.sh similarity index 100% rename from xctest/build_and_test.sh rename to testing/xctest/build_and_test.sh diff --git a/xctest/test.swift b/testing/xctest/test.swift similarity index 100% rename from xctest/test.swift rename to testing/xctest/test.swift