Foundation
APNS
APFS
GameKit
IOUSBHost
Swift Packages
App Tracking Transparency
GameplayKit
MetricKit
Mobile Core Services
Subscriptions
App Clips
AGL
Wallet
Watch Connectivity
SCSIControllerDriverKit
Forums Feedback
Force Feedback Control
External Graphics Processors
Files and Storage .
IOBluetooth
Community
Developer Tools
ML Compute
FWAUserLib
Image I/O
Screen Saver
Swift Student Challenge
Apple Music API
Games Discuss games
AudioToolbox
Xcode.
Maps Web Snapshots
WatchKit
Extensions
Accounts
Apple Watch.
Messages app.
CarPlay EventKit and EventKitUI.
iOS, iPadOS, watchOS, tvOS, and macOS apps.
App Store
(FPS).
iPad
Media Player
Exception Handling
External Accessory
iOS iOS iPhone.
Xcode Server Xcode projects.
Face ID
CloudKit
App ID
Metal
MusicKit
StoreKit Test
Swift
xcselectmacOS SDK
Beta
WebKit JS
APIs.
Frameworks
Asset Catalog
Education and Kids
Game Controller
Inter-process communication
App Review Apple guidelines.
Messages
SpriteKit
vmnet
ARKit
Automatic Assessment Configuration
MetalKitModel I/O using MetalKit.
Multipeer Connectivity
MusicKit JS
StoreKit
Swift Playgrounds Foundation.
APNS (APNs).
APFS
GameKit
IOUSBHost .
Swift Packages
App IOSurface.
iPadOS
VideoToolbox (ASan), (MTC), Thread Sanitizer (TSan), (UBSan).
Game Porting Toolkit
Core Transferable Declare a transfer representation for your model types to participate in system sharing and data transfer operations.
WWDC23 Challenges Share your creations from the WWDC22
WWDC23 Discuss the latest Apple technologies announced at WWDC23.
WorkoutKit
visionOS Apple Vision Pro.
WebXR .
SwiftData .
DockKit API
DeviceDiscoveryUI
Apple Intelligence
AdAttributionKit
Platform SSO
TabletopKit
Swift Testing
RSS for tagSwift Testing is a framework with expressive and intuitive APIs that make testing your Swift code a breeze.
Posts under Swift Testing tag
5 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
From the Documentation of .timeLimit(_:):
Test timeouts do not support high-precision, arbitrarily short durations due to variability in testing environments. The time limit must be at least one minute, and can only be expressed in increments of one minute.
Unit Tests are usually considered too long when they take more than 0.1 seconds. So a minimal time limit of on minute is completely useless for unit tests.
Is there a similar trait in Swift Testing to handle millisecond time limits?
Hello everyone,
I’m encountering an issue with my Swift Testing suite where state changes made in one test method do not persist to another. I am using Swift’s @Suite and @Test annotations to group and serialize my tests, but it seems that the state is not being carried over between the tests. The second function fails with:
Expectation failed: (string → nil) != nil
Here is my example code:
import Testing
@Suite(.serialized)
struct createCheckTests {
var value = 25
var string: String? = nil
@Test("Create string")
mutating func stringCreation() {
#expect(value > 0)
string = "Value is: \(value)"
}
@Test("Check string")
func stringCheck() {
#expect(string != nil, "The string is nil")
print("\(String(describing: string))")
}
}
What is the correct way to approach such a scenario where I want to test two functions that are related, one to generate some value and one to check that generated value against it initial value using Suites to group and isolate them from other tests?
Thanks.
Is it a known issue that when attempting to test SwiftData objects with relationships in Swift Testing there are errors that do not occur when the app is running?
Example:
@Relationship(deleteRule: .cascade, inverse: \MBAccount.book) var accounts: [MBAccount] = []
and
@Relationship var book: Microbook?
Then the test:
let book = Microbook(name: "Julia's Cupcakes")
let account1 = MBAccount(name: "Chase Business Account")
let account2 = MBAccount(name: "Cash Drawer")
account1.book = book
account2.book = book
#expect(account1.name == "Chase Business Account")
#expect(account2.type == "asset")
}
Produces a fatal error while running test:
SwiftData/PersistentModel.swift:321: Fatal error: Unable to find relationship on MBAccount for KeyPath \MBAccount.book
Any ideas?
Currently Swift Testing has much less features than XCTest, so the adoption will be very slow from our side. Notable features we miss are UI tests, performance tests and attachments.
I did not want to create many issues in Swift Testing GitHub project as lots of these shortcoming are most probably tracked internally (I can see lots of references to radars in GitHub issues.)
So, my question is: Is it a good idea to wait with wider adoption or should we experiment with other tools like swift Benchmarks?