gpt4 book ai didi

iOS KIF 测试失败

转载 作者:行者123 更新时间:2023-11-28 21:08:26 25 4
gpt4 key购买 nike

我正在尝试在示例应用中使用 KIF 学习自动化 UI 测试。我的简单测试不断失败。我的代码:

#import <XCTest/XCTest.h>
#import <KIF/KIF.h>

@interface AutomatedUITestsSampleUITests : KIFTestCase

@end

@implementation AutomatedUITestsSampleUITests

- (void)setUp {
[super setUp];

// Put setup code here. This method is called before the invocation of each test method in the class.

// In UI tests it is usually best to stop immediately when a failure occurs.
self.continueAfterFailure = NO;
// UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
[[[XCUIApplication alloc] init] launch];

// In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
}

- (void)tearDown {
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}

- (void)testExample {

[tester waitForViewWithAccessibilityLabel:@"LOGIN - Button"];

[tester tapViewWithAccessibilityLabel:@"LOGIN - Button" traits:UIAccessibilityTraitButton];
}

我已将辅助功能标签 LOGIN - Button 设置为 Storyboard中的 UIButton,同时辅助功能已启用。

我在控制台中得到这个:

Test Case '-[AutomatedUITestsSampleUITests testExample]' started.
t = 0.00s Start Test at 2017-06-16 13:45:07.071
t = 0.00s Set Up
t = 0.04s Launch com.UITests.AutomatedUITestsSample
t = 4.63s Waiting for accessibility to load
t = 8.77s Wait for app to idle
t = 10.48s Tear Down
Test Case '-[AutomatedUITestsSampleUITests testExample]' failed (10.868 seconds).
Test Suite 'AutomatedUITestsSampleUITests' failed at 2017-06-16 13:45:17.939.
Executed 1 test, with 1 failure (1 unexpected) in 10.868 (12.735) seconds
Test Suite 'AutomatedUITestsSampleUITests.xctest' failed at 2017-06-16 13:45:17.940.
Executed 1 test, with 1 failure (1 unexpected) in 10.868 (12.739) seconds
Test Suite 'All tests' failed at 2017-06-16 13:45:17.941.
Executed 1 test, with 1 failure (1 unexpected) in 10.868 (12.743) seconds

这是一个非常简单的测试。为什么会失败?提前致谢。

最佳答案

如果您有权访问 XCUIApplication,则您的项目配置有问题。 KIF 测试目标应该是“单元测试目标”,而不是“UI 测试目标”。如果配置正确,则无需启动应用程序(也不可能进行应用程序启动操作)——它会在单元测试开始时启动。当您使用 UI 测试目标时,您的测试在单独的进程中运行,并且 KIF 无权访问您的应用。

我建议使用 this guide 再次配置您的测试目标

关于iOS KIF 测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44584355/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com