【问题标题】:Test Application by looping through a pattern of values in UITextField通过循环遍历 UITextField 中的值模式来测试应用程序
【发布时间】:2016-12-26 10:00:37
【问题描述】:

我想通过在 UITextField 中输入 1 到 10000 的值并按下“开始”UIButton 来测试我的应用程序。

并且知道执行转场的条件。

在 UITextField 中输入值 1 - 10000 时,如何定义自动测试的测试标准?

与我的问题完全匹配的另一种情况:

在测试计算器应用程序时,我需要检查所有可能的运算和数字。我们可以自动化测试计算器上的随机点击并检查输出吗?

【问题讨论】:

  • 您能否详细说明您的问题。您提供的信息不足以理解您的问题。
  • 不清楚您是否需要随机输入或 1 到 10000 之间的广泛输入的解决方案。当您说您想知道何时执行转场时,您期望什么转场以及什么segue 完成后有什么变化?
  • 我只想通过将值 1 到 10000 放入 UITextfield 进行测试,然后简单地检查会发生什么。

标签: objective-c xcode xcode-ui-testing


【解决方案1】:

您可以使用循环来尝试 1 到 10000 之间的每个值。对于每个值,将其输入到文本字段中,按下按钮,看看会发生什么。我不确定您期望发生什么,所以我刚刚编写了检查标签是否出现的代码 - 您应该将其更改为您认为会断言正确结果已经发生的任何内容。

XCUIApplication *app = [[XCUIApplication init] alloc];
XCUIElement *textField = [[app.textFields matchingIdentifier: "myTextField"] elementBoundByIndex: 0];
XCUIElement *goButton = [[app.buttons matchingIdentifier: "goButton"] elementBoundByIndex: 0];

for (NSNumber i = 1; i <= 10000; i++) {
    NSString *n = [NSString stringWithFormat:@"%d", i];
    [textField tap];
    [textField typeText: n];
    [goButton tap];

    // Define what it is you expect to happen
    BOOL expectedOutcome = [[app.staticTexts matchingIdentifier: "myLabel"] elementBoundByIndex: 0].exists;
    XCTAssert(expectedOutcome, [NSString stringWithFormat:@"Unexpected result for %d", i])
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-11-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 2018-01-24
    • 2021-09-14
    相关资源
    最近更新 更多