-
Hello, struct TestDependency: TestDependencyKey, Sendable {
let add: @Sendable (Int) -> Void
static var testValue: TestDependency {
let array = OSAllocatedUnfairLock<Int?>(initialState: nil)
return .init { newValue in
array.withLock { value in
if value != nil {
fatalError()
} else {
value = newValue
}
}
}
}
}
extension DependencyValues {
var test: TestDependency {
get { self[TestDependency.self] }
set { self[TestDependency.self] = newValue }
}
} And then following import XCTest
class TestCase: XCTestCase {
@Dependency(\.test) var test
func testSomething() {
test.add(1)
}
} The import Testing
@Suite(.serialized) struct TestSuite {
@Dependency(\.test) var test
@Test func testSomething() {
test.add(1)
}
} ... does run into the Edit 1: You will need to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
I believe we have documentation on this somewhere, but currently |
Beta Was this translation helpful? Give feedback.
I believe we have documentation on this somewhere, but currently
.dependency
does not work with parameterized tests or repeatedly run tests. We are currently doing some hacky things to support.dependency
in the first place, but really we need new tools from Swift Testing to support this properly. Those tools are coming, hopefully in Swift 6.1, called Test Scoping Traits.