@@ -39,22 +39,20 @@ This will generate a new directory called _MyLibrary_ with the following files:
3939In fact, SwiftPM generated a "Hello, world!" project for us, including some unit tests!
4040We can run the tests by running ` swift test ` in our terminal.
4141
42- ~~~ bash
42+ ~~~ no-highlight
4343$ swift test
4444Building for debugging...
4545[5/5] Linking MyLibraryPackageTests
4646Build complete! (7.91s)
47- Test Suite ' All tests' started at 2023-08-29 18:59:31.328
48- Test Suite ' MyLibraryPackageTests.xctest' started at 2023-08-29 18:59:31.329
49- Test Suite ' MyLibraryTests' started at 2023-08-29 18:59:31.329
50- Test Case ' -[MyLibraryTests.MyLibraryTests testExample]' started.
51- Test Case ' -[MyLibraryTests.MyLibraryTests testExample]' passed (0.001 seconds).
52- Test Suite ' MyLibraryTests' passed at 2023-08-29 18:59:31.330.
53- Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
54- Test Suite ' MyLibraryPackageTests.xctest' passed at 2023-08-29 18:59:31.330.
55- Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
56- Test Suite ' All tests' passed at 2023-08-29 18:59:31.330.
57- Executed 1 test, with 0 failures (0 unexpected) in 0.001 (0.002) seconds
47+ Test Suite 'All tests' started at 2025-08-01 14:02:39.232.
48+ Test Suite 'All tests' passed at 2025-08-01 14:02:39.233.
49+ Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
50+ ◇ Test run started.
51+ ↳ Testing Library Version: 6.1 (43b6f88e2f2712e)
52+ ↳ Target Platform: arm64-apple-macosx
53+ ◇ Test example() started.
54+ ✔ Test example() passed after 0.001 seconds.
55+ ✔ Test run with 1 test passed after 0.001 seconds.
5856~~~
5957
6058## A small library
@@ -86,39 +84,41 @@ Now let's add a unit test for this strongly typed Email API.
8684Replace the example content of ` MyLibraryTests.swift ` with the following code:
8785
8886~~~ swift
87+ import Testing
8988@testable import MyLibrary
90- import XCTest
9189
92- final class MyLibraryTests : XCTestCase {
93- func testEmail () throws {
90+ struct MyLibraryTests {
91+ @Test func email () throws {
9492 let email
= try Email (
" [email protected] " )
95- XCTAssertEqual (email.
description , " [email protected] " )
93+ #expect (email.
description == " [email protected] " )
9694
97- XCTAssertThrowsError (try Email (" invalid" ))
95+ #expect (throws : (any Error ).self ) {
96+ try Email (" invalid" )
97+ }
9898 }
9999}
100100~~~
101101
102102Once we save that, we can run the tests again:
103103
104104~~~ no-highlight
105- ❯ swift test
105+ $ swift test
106106Building for debugging...
107107[5/5] Linking MyLibraryPackageTests
108108Build complete! (3.09s)
109- Test Suite 'All tests' started at 2023 -08-29 19:01:08.640
110- Test Suite 'MyLibraryPackageTests.xctest' started at 2023 -08-29 19:01:08.641
111- Test Suite 'MyLibraryTests' started at 2023-08-29 19:01:08.641
112- Test Case '-[MyLibraryTests.MyLibraryTests testEmail]' started.
113- Test Case '-[MyLibraryTests.MyLibraryTests testEmail]' passed (0.002 seconds).
114- Test Suite 'MyLibraryTests' passed at 2023-08-29 19:01:08.643.
115- Executed 1 test, with 0 failures (0 unexpected) in 0.002 (0.002) seconds
116- Test Suite 'MyLibraryPackageTests.xctest' passed at 2023-08-29 19:01:08.643 .
117- Executed 1 test, with 0 failures (0 unexpected) in 0.002 (0.002) seconds
118- Test Suite 'All tests' passed at 2023-08-29 19:01:08.643 .
119- Executed 1 test, with 0 failures (0 unexpected) in 0.002 (0.003) seconds
109+ Test Suite 'All tests' started at 2025 -08-01 14:24:32.687.
110+ Test Suite 'All tests' passed at 2025 -08-01 14:24:32.689.
111+ Executed 0 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
112+ ◇ Test run started.
113+ ↳ Testing Library Version: 6.1 (43b6f88e2f2712e)
114+ ↳ Target Platform: arm64-apple-macosx
115+ ◇ Suite MyLibraryTests started.
116+ ◇ Test email() started .
117+ ✔ Test email() passed after 0.001 seconds.
118+ ✔ Suite MyLibraryTests passed after 0.001 seconds .
119+ ✔ Test run with 1 test passed after 0.001 seconds.
120120~~~
121121
122122---
123123
124- > The source code for this guide can be found [ on GitHub] ( https://github.com/apple/swift-getting-started-package-library )
124+ > The source code for this guide can be found [ on GitHub] ( https://github.com/apple/swift-getting-started-package-library ) .
0 commit comments