問題タブ [xctestexpectation]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
swift - XCTest 非同期関数 Swift
私は XCTest を初めて使用します。モデル、ビュー、コントローラーでコードを構造化しました。
したがって、コントローラーはモデルからデータを取得し、データを取得すると、コントローラーはビューを更新します。だから私は私のコントローラとビューを次のように持っています
コントローラ:
意見:
ここに私のXCTestがあります
自分ができるということがわかっている
しかし、どこに置くべきexpectation.fulfill()ですか?
どんな助けでも大歓迎です。ありがとう
swift - XCTWaiter().wait with XCTestExpectation and NSPredicate seems to fail
I am trying to write unit tests where I want my test case to wait for a variable in a certain class to change. So I create an expectation with a predicate and wait for the value to change using XCTWaiter().wait(for: [expectation], timeout: 2.0), which I assume is the correct method to use.
The following code works as expected:
A variable (x) is set to 0 and then changes to 1 after 0.5s by the start() function. The predicate waits for that var (x) to change. That works: result is set to .completed and the var actually is set to 1. Yeah :-)
However, when the variable that I want to observe is not a local var, but is in a class somewhere, it no longer works. Consider the following code fragment:
It is quite similar to the first piece of code, but this always ends after 2 seconds with result being .timedOut. I can't see what I am doing wrong. I use a variable from object myClass that I pass into the expectation instead of a local var and object 'self'. (The class var myClass.y is actually set to 1 when the test ends.)
I tried replacing XCTNSPredicateExpectation(predicate:object) with expectation(for:evaluatedWith:handler), but that didn't make any difference.
Many examples here on StackOverflow use a predicate that checks for exists in XCUIElement. But I am not testing UI; I just want to check if some var in some class has changed within a timeout period. I don't understand why that is so different from checking var exists in XCUIElement.
Any ideas?! Thank you in advance!