You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello,
I've recently been rewriting some dependency related tests in swift-testing but I came across a discrepancy to XCTest, where I could not find anything in the documentation. Consider this dependency:
structTestDependency:TestDependencyKey,Sendable{letadd:@Sendable(Int)->VoidstaticvartestValue:TestDependency{letarray=OSAllocatedUnfairLock<Int?>(initialState:nil)return.init { newValue in
array.withLock{ value inif value !=nil{fatalError()}else{
value = newValue
}}}}}extensionDependencyValues{vartest:TestDependency{get{self[TestDependency.self]}set{self[TestDependency.self]= newValue }}}
The fatalError() will never trigger here, because after each test function, the cached dependency is reset (I think). However, the same code with swift-testing:
... does run into the fatalError. Is this just to be expected, because of differences in swift-testing and XCTest? If yes, I think if it was not yet documented it makes sense to document this somewhere. Or are there workarounds to get the same behavior?
Edit 1: You will need to Run "TestSuite" repeatedly, to run into this problem
Edit 2: Same happens with SwiftTestingTestscachePollution1 and cachePollution2
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hello,
I've recently been rewriting some dependency related tests in
swift-testing
but I came across a discrepancy toXCTest
, where I could not find anything in the documentation. Consider this dependency:And then following
XCTestCase
:The
fatalError()
will never trigger here, because after each test function, the cached dependency is reset (I think). However, the same code withswift-testing
:... does run into the
fatalError
. Is this just to be expected, because of differences inswift-testing
andXCTest
? If yes, I think if it was not yet documented it makes sense to document this somewhere. Or are there workarounds to get the same behavior?Edit 1: You will need to
Run "TestSuite" repeatedly
, to run into this problemEdit 2: Same happens with
SwiftTestingTests
cachePollution1
andcachePollution2
Beta Was this translation helpful? Give feedback.
All reactions