基于 KIF 的 iOS UI 自动化测试和持续集成(5)

发表于:2017-03-10来源:美团点评技术团队作者:美团点评技术团队点击数: 标签:iOSKIF
模拟用户旋转设备: - (void)simulateDeviceRotationToOrientation:(UIDeviceOrientation)orientation; 对当前屏幕截图并存储到硬盘中:- (void)captureScreenshotWithDescription:(NSStrin
    模拟用户旋转设备:          - (void)simulateDeviceRotationToOrientation:(UIDeviceOrientation)orientation;
    对当前屏幕截图并存储到硬盘中:- (void)captureScreenshotWithDescription:(NSString *)description;
(3)用例组织

设计实现单个测试用例步骤如下:

  • a. 设置测试所需要的环境;
  • b. 测试用例的测试逻辑;
  • c. 恢复App至此次测试前状态。

a、c步骤可用 beforeEach、afterEach 来实现,这样保证了每个用例之间的独立性和用例运行的稳定性。
一般来说,可将用例按功能分成若干个用例集,每个用例集按校验点或者功能点分成若干个用例,这样方便测试用例的管理和维护。 某些含有耗费时间多、耗费资源多的公共操作的用例可以集合成一个用例集,在用例集运行前统一执行。设计实现用例集步骤如下:

  • a. 设置用例集需要的环境、公共操作;
  • b. 设计各个用例;
  • c. 恢复 App 至用例集测试的初始状态。

a、c步骤可用 beforeAll、afterAll 来实现,下图展示了一个用例集的书写示例:

#import "TimerTests.h"
#import "KIFUITestActor+AccessibilityLabelAddition.h"
#import "KIFUITestActor+IdentifierAdditions.h"
#import "KIFUITestActor+TimerAdditions.h"
@implementation TimerTests
- (void)beforeAll
{
    [tester setDebugModel];
}
- (void)afterAll
{
    [tester resetDebugModel];
    [tester clearHistory];
}
- (void)beforeEach
{
    [tester setDebugModel];
}
- (void)afterEach
{
    [tester clearParams];
}
- (void)testNameedTask
{
    [tester enterText:@"myTask" intoViewWithAccessibilityLabel:@"Task Name Input"];
    [tester enterWorktime:10 Breaktime:4 Repetitions:5];
    [tester tapViewWithAccessibilityLabel:@"Start Working"];
    [tester waitForViewWithAccessibilityLabel:@"myTask"];
    [tester waitForViewWithAccessibilityLabel:@"Start Working"];
}
- (void)testnoNameTask
{
    [tester enterWorktime:10 Breaktime:4 Repetitions:5];
    [tester tapViewWithAccessibilityLabel:@"Start Working"];
    [tester waitForViewWithAccessibilityLabel:@"myTask"];
    [tester waitForViewWithAccessibilityLabel:@"Start Working"];
}
- (void)testPresetTask
{
    [tester tapViewWithAccessibilityLabel:@"Presets"];
    [tester tapRowAtIndexPath:@"Classic" inTableViewWithAccessibilityIdentifier:@"Presets List"];
    [tester tapViewWithAccessibilityLabel:@"Start Working"];
    [tester waitForViewWithAccessibilityLabel:@"myTask"];
    [tester waitForViewWithAccessibilityLabel:@"Start Working"];
}
@end
 



           

原文转自:https://zhuanlan.zhihu.com/p/22283843