2

我是 iOS、xcode、KIF 框架、Objective C 的新手。我的第一个任务是使用 KIF 编写测试代码。如果 KIF 有条件语句,它肯定会容易得多。

基本上是这样的:

if ([tester existsViewWithAccessibilityLabel:@"Login"]) {
    [self login];
}
// continue with test in a known state

当您一次运行一项测试时,KIF 在测试后退出应用程序。如果您一次运行所有测试,它不会在测试之间退出 - 要求测试人员非常非常小心应用程序的状态(这非常耗时且不好玩)。

4

3 回答 3

1

测试框架通常不会实现 if 条件,因为它们已经以其原生形式存在。
您可以查看测试框架的源代码以了解它如何进行“如果状态检查”。这将教你如何去做你可能想做的大多数事情(即使在功能测试期间做这些事情并不总是一个好主意)。你也可以看这里:我可以用 KIF 检查屏幕上是否存在视图吗?

此外,您的测试本质上应该是自信的,遵循以下工作流程:

 given:
    the user has X state setup  
    (here you write code to assertively setup the state)

    It is OK and preferred to isolate your tests and setup
    the "given" state (e.g. set login name in the model directly without going
    through the UI) as long as you have covered that behavior in another test. 

    When:
    The user tries to do X
    (here you tap something etc..)

    Then:<br>
    The system should respond with Z
    (here you verify the system did what you need it) 
于 2014-05-22T14:54:14.050 回答
0

每次测试的第一步应该是将应用程序重置为已知状态,因为这是保证可重复测试的唯一方法。一旦您开始将条件代码放入测试本身,您就会在结果中引入不可预测性。

于 2015-04-03T18:42:28.590 回答
-1

如果可以找到它,您总是可以尝试tryFindingViewWithAccessibilityLabel:error:返回 true 否则返回 false 的方法。

if ([tester tryFindingViewWithAccessibilityLabel(@"login") error: nil]){
    //Test things
}
于 2015-06-09T19:21:31.613 回答