Skip to content

Commit

Permalink
move around
Browse files Browse the repository at this point in the history
  • Loading branch information
qyang-nj committed Oct 8, 2024
1 parent d212701 commit d3891ef
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
44 changes: 44 additions & 0 deletions articles/iOSTesting.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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).

<details>
<summary>Output from XCTest</summary>

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
</details>

<details>
<summary>Output from Swift Testing</summary>

◇ 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.

</details>

2 changes: 1 addition & 1 deletion xctest/README.md → testing/xctest/README.md
Original file line number Diff line number Diff line change
@@ -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.

Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit d3891ef

Please sign in to comment.