ios - XCTAssertTrue 在测试 iOS UI 时不会失败

标签 ios objective-c xcode-ui-testing

我正在测试别人编写的计算器。我正在尝试使用 xcode 7 来测试所有基本功能。

这是我目前正在运行的不会失败的测试。我使用了新的录音功能来获得所有的按钮点击。但是,我不确定如何断言我得到的值是正确的。

- (void)testExample {
// Use recording to get started writing UI tests.

XCUIApplication *app = [[XCUIApplication alloc] init];
[app.buttons[@"6"] tap];
[app.buttons[@"+"] tap];
[app.buttons[@"3"] tap];
[app.buttons[@"="] tap];

//what the equation should return (9 in this case)
XCUIElement *display = app.staticTexts[@"199"];
XCTAssertTrue(display);

//what the equation should look like (6 + 3 in this case)
display = app.staticTexts[@"222+5553"];
XCTAssertTrue(display);

}

最佳答案

您主要想检查带有该标签的 XCUIElement exists:

XCTAssertTrue(display.exists)

关于ios - XCTAssertTrue 在测试 iOS UI 时不会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32800700/

相关文章:

objective-c - 如何检测 OSX 管理员密码提示?

objective-c - 对 Objective-c View 、代表和导出的混淆

ios - 您可以从命令行运行特定的 Xcuitest 吗?

点击第二个文本字段时 iOS UI 测试错误

ios - 以编程方式打开 iOS Touch ID 设置

iphone - NSTimer、NSTask、NSThread 和 NSRunloop 之间的基本区别是什么?

objective-c - NSView 的 -layout 方法的覆盖到底应该如何工作?

ios - 使用本地化的 app.staticTexts 进行 UI 测试 (XCTest)

ios - 当我选中一个复选框时,所有复选框都被选中(Swift)

iphone - NSURLConnection 和 "chunked"传输编码