@@ -17,33 +17,20 @@ Start running tests in a new or existing XCTest-based test target.
17
17
18
18
## Overview
19
19
20
- The testing library is not (yet) integrated into Swift Package Manager, but a
21
- temporary mechanism is provided for developers who want to start using it with
22
- their Swift packages.
23
-
24
- - Warning: This functionality is provided temporarily to aid in integrating the
25
- testing library with existing tools such as Swift Package Manager. It will be
26
- removed in a future release.
20
+ The testing library has experimental integration with Swift Package Manager's
21
+ ` swift test ` command and can be used to write and run tests alongside, or in
22
+ place of, tests written using XCTest. This document describes how to start using
23
+ the testing library to write and run tests.
27
24
28
25
To learn how to contribute to the testing library itself, see
29
26
[ Contributing to ` swift-testing ` ] ( https://github.com/apple/swift-testing/blob/main/CONTRIBUTING.md ) .
30
27
31
28
### Downloading a development toolchain
32
29
33
- A recent ** Swift 5.10 development snapshot** toolchain is required to use the
34
- testing library. Visit [ swift.org] ( https://www.swift.org/download/#swift-510-development )
35
- to download and install a toolchain from the section titled
36
- ** Snapshots — Swift 5.10 Development** .
37
-
38
- @Comment {
39
- - Bug: A compiler bug in the Swift main branch is temporarily preventing its
40
- use with the testing library. ([ swift- #69096 ] ( https://github.com/apple/swift/issues/69096 ) )
41
- }
42
-
43
- <!-- A recent **development snapshot** toolchain is required to use the testing
30
+ A recent ** development snapshot** toolchain is required to use the testing
44
31
library. Visit [ swift.org] ( https://www.swift.org/download/#trunk-development-main )
45
32
to download and install a toolchain from the section titled
46
- **Snapshots — Trunk Development (main)**.-->
33
+ ** Snapshots — Trunk Development (main)** .
47
34
48
35
Be aware that development snapshot toolchains are not intended for day-to-day
49
36
development and may contain defects that affect the programs built with them.
@@ -81,22 +68,6 @@ Then, add the testing library as a dependency of your existing test target:
81
68
)
82
69
```
83
70
84
- ### Adding test scaffolding
85
-
86
- Add a new Swift source file to your package's test target named
87
- "Scaffolding.swift". Add the following to it:
88
-
89
- ``` swift
90
- import XCTest
91
- import Testing
92
-
93
- final class AllTests : XCTestCase {
94
- func testAll () async {
95
- await XCTestScaffold.runAllTests (hostedBy : self )
96
- }
97
- }
98
- ```
99
-
100
71
You can now add additional Swift source files to your package's test target that
101
72
contain those tests, written using the testing library, that you want to run
102
73
when you invoke ` swift test ` from the command line or click the
@@ -119,18 +90,57 @@ export TOOLCHAINS=swift
119
90
120
91
In Xcode, open the ** Xcode** menu, then the Toolchains submenu, and select the
121
92
development toolchain from the list of toolchains presented to you&mdash ; it will
122
- <!-- be presented with a name such as "Swift Development Toolchain 2023-01-01 (a)".-->
123
- be presented with a name such as "Swift 5.10 Development Snapshot 2023-01-01 (a)".
93
+ be presented with a name such as "Swift Development Toolchain 2023-01-01 (a)".
124
94
125
95
### Running tests
126
96
97
+ Navigate to the directory containing your package and run the following command:
98
+
99
+ ``` sh
100
+ swift test --enable-experimental-swift-testing
101
+ ```
102
+
103
+ Swift Package Manager will build and run a test target that uses the testing
104
+ library as well as a separate target that uses XCTest. To only run tests written
105
+ using the testing library, pass ` --disable-xctest ` as an additional argument to
106
+ the ` swift test ` command.
107
+
108
+ #### Swift 5.10
109
+
110
+ As of Swift 5.10, the testing library is not integrated into Swift Package
111
+ Manager, but a temporary mechanism is provided for developers who want to start
112
+ using it with their Swift packages and the Swift 5.10 toolchain.
113
+
114
+ - Warning: This functionality is provided temporarily to aid in integrating the
115
+ testing library with existing tools such as Swift Package Manager. It will be
116
+ removed in a future release.
117
+
118
+ To use the testing library with Swift 5.10, add a new Swift source
119
+ file to your package's test target named "Scaffolding.swift". Add the following
120
+ code to it:
121
+
122
+ ``` swift
123
+ import XCTest
124
+ import Testing
125
+
126
+ final class AllTests : XCTestCase {
127
+ func testAll () async {
128
+ await XCTestScaffold.runAllTests (hostedBy : self )
129
+ }
130
+ }
131
+ ```
132
+
127
133
Navigate to the directory containing your package, and either run ` swift test `
128
134
from the command line or click the Product  ;&rarr ;  ; Test menu item in
129
- Xcode. You're done!
135
+ Xcode.
130
136
131
137
Tests will run embedded in an ` XCTestCase ` -based test function named
132
138
` testAll() ` . If a test fails, ` testAll() ` will report the failure as its own.
133
139
140
+ #### Swift 5.9 or earlier
141
+
142
+ The testing library does not support Swift 5.9 or earlier.
143
+
134
144
## Topics
135
145
136
146
- `` XCTestScaffold ``
0 commit comments