KIF を使い始めたばかりですが、現在の構成で非同期にロードされたテーブル ビューをテストするのに問題があります。
アプリにボタン付きのホームスクリーンがあります。そのボタンが押されると、モーダル ビュー コントローラーが表示されます。
- (void)viewDidLoad
{
[super viewDidLoad];
// Setup accessibility
self.theTableView.accessibilityLabel = @"My List";
// Register for notifications
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectsLoadedNotification:) name:kNotificationObjectsLoaded object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectsFailedToLoadNotification:) name:kNotificationObjectsFailedToLoad object:nil];
// Start loading new data
[[MyListObjectManager sharedInstance] requestObjects];
}
これで、KIF で次のようなテストをセットアップしました。
+ (id)scenarioToSelecList
{
KIFTestScenario *scenario = [KIFTestScenario scenarioWithDescription:@"Test that a user can select an item from my list."];
[scenario addStep:[KIFTestStep stepToTapViewWithAccessibilityLabel:@"List"]];
[scenario addStep:[KIFTestStep stepToWaitForNotificationName:kNotificationObjectsLoaded object:nil]];
[scenario addStep:[KIFTestStep stepToTapRowInTableViewWithAccessibilityLabel:@"My List" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]];
}
テストを実行すると、KIF はオブジェクトがロードされたという通知をまったく見ません。
デバッグでは、viewDidLoad メソッドの [objectManager requestObjects] 呼び出しを、3 秒後にオブジェクトを要求する非同期呼び出しに置き換えました。
[[MyListObjectManager sharedInstance] performSelector:@selector(requestObjects) withObject:nil afterDelay:3.0];
これを行うと、KIF 出力に次のように表示されます。
PASS (0.90s): Tap view with accessibility label "Find Books"
PASS (3.02s): Wait for notification "notificationObjectsLoaded"
これにより、元の問題は、最初のステップの実行が完了する前に、私が待っている通知が発行されることだと思います。
では、最初のステップが完了するまでに 0.9 秒かかるのはなぜでしょうか? ステップから戻る前に、モーダル アニメーションが終了するのを待っていますか? その場合、オブジェクトをロードするリクエストは、アニメーションよりも速く完了します。
これを KIF でどのように処理する必要がありますか? または、より適切なテーブルビューの非同期データをロードする別のアプローチがありますか?