i am using rxswift to process service data, and i use the xctest to test it, in xcode15, the test function test success, but when i use xcode16, the test function always failed, anyone can help me? thaks a lot
// ViewModel
private let models = BehaviorRelay<[String]>(value: [])
lazy var modelsDriver: Driver<[String]> = {
return models.asDriver().skip(1)
}()
func requestData() {
Service.get { data in
DispatchQueue.main.async {
models.accept(data.models)
}
}
}
// XCTest
func testRequest() async {
let expectation = expectation(description: "RequestTest")
DispatchQueue.main.async {
self.viewModel.modelsDriver.drive(onNext: { models in
XCTAssertEqual(mdoels.count, 4)
expectation.fulfill()
}).disposed(by: self.disposeBag)
}
viewModel.requestData()
await fulfillment(of: [expectation], timeout: 5.0)
}
i tried use Task api like this,
Task {
viewModel.requestData()
}
but still failed. if a set timeout to 2min, i got the same error, and my simulator was stuck.
if i just run a simple test like this
func testData() {
XCTAssertTrue(2 > 1)
}
my simulator was stuck, but if a run a UITest, the simulator works well
4