xctest

XCTest app tests and permissions alerts

主宰稳场 提交于 2019-12-11 01:38:59
问题 I'm writing XCTest app tests that test some UIViewControllers by calling presentViewController on the UIApplication rootViewController . This works fine, except for permissions dialogs. Some of the UIViewControllers make the system pop permissions dialogs for things like camera or microphone access. I'm not sure how to dismiss them. If this were a UI test, I could use addUIInterruptionMonitorWithDescription and tap the alert away. However, I'm not sure how to make this work. Can an app test

Access ID does not work when testing a textfield with `isSecureTextEntry = true`

落花浮王杯 提交于 2019-12-11 00:43:53
问题 So i am trying to access and confirm the presence of a password textfield in my uitests but as soon as assign their isSecureTextEntry = true the tests can no longer find them by the accessID. Does any one know why? and if there is a way around this so that i can find them and use them in the tests? Preferably so that i can still use the access ID to locate them in the tests. My test is very simple: func testHasPasswordTextField() { let passwordTextField = app.textFields[AccesID

Xcode 7 - How to initiate interface recording for UI Testing?

蹲街弑〆低调 提交于 2019-12-10 19:59:32
问题 I'm looking at the WWDC 2015 session 104 "What's new in Xcode" and see that in Xcode 7 I can record interface unit tests to automate clicking on buttons, enter text, etc. I have a new project created with UITests included, but how do I actually start recording interface interactions for UITests? Here's the snippet included in the test: - (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

XCTest for existing project

柔情痞子 提交于 2019-12-10 19:44:03
问题 I have a big(about 700 modules) iOS project. Now I need to make unit tests for existing code(before we didn't use it). I've added new XCTest test target for my target and started to write my first test. But after compilation I've got some link errors, because modules from my project weren't be included to test target. Have I include all my modules to test target? Or there is easier way to make test target? 回答1: Application files DO NOT need to be included within XCTest targets. Only test

XCTestCase简单介绍和使用

谁说我不能喝 提交于 2019-12-10 18:23:34
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> ‍ ‍ 为什么我们需要测试? ‍ ‍ 测试用例使我们的代码质量变得可靠,同时让我们能够放心地重构或者修改代码,并保证我们的修改没有破坏其他部分。而且我们可以在项目开始的第一天就能运行我们的代码,而不用等到万事俱备。 XCTestCase XCTest作为我们的测试框架是因为它非常简单并且与 Xcode的IDE直接集成。 每个XCode创建iOS的工程中都有一个叫做”工程名Tests”的分组,这个分组里就是XCTestCase的子类,XCTest中的测试类都是继承自XCTestCase。 例如新建一个工程,命名为Demo,就能看到如图 #import <UIKit/UIKit.h>#import <XCTest/XCTest.h>@interface DemoTests : XCTestCase@end@implementation DemoTests - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class.} - (void)tearDown { // Put teardown code here.

XCTestCase简单介绍和使用

落爺英雄遲暮 提交于 2019-12-10 18:23:21
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> ‍ ‍ 为什么我们需要测试? ‍ ‍ 测试用例使我们的代码质量变得可靠,同时让我们能够放心地重构或者修改代码,并保证我们的修改没有破坏其他部分。而且我们可以在项目开始的第一天就能运行我们的代码,而不用等到万事俱备。 XCTestCase XCTest作为我们的测试框架是因为它非常简单并且与 Xcode的IDE直接集成。 每个XCode创建iOS的工程中都有一个叫做”工程名Tests”的分组,这个分组里就是XCTestCase的子类,XCTest中的测试类都是继承自XCTestCase。 例如新建一个工程,命名为Demo,就能看到如图 #import <UIKit/UIKit.h>#import <XCTest/XCTest.h>@interface DemoTests : XCTestCase@end@implementation DemoTests - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class.} - (void)tearDown { // Put teardown code here.

Cannot find stackview in accessibility indicator in XCUITest

半世苍凉 提交于 2019-12-10 17:49:14
问题 I'm writing UI test cases for my view controller.it has three views 1.A header view ->Stackview -> 4 buttons 2.table View 3.footer view - > 5 buttons All views are accessible except stackview and its child buttons Can anyone guide me how do i get reference of stackview and its child elements? 回答1: Set the header view and stack view to be inaccessible and the child elements to be accessible. You can do this using the UIAccessibility API, setting isAccessibilityElement to false for the

Segmentation fault 11 when code coverage is turned on in Swift

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-10 17:29:47
问题 While I am running unit tests with XCTest in Swift, they run fine when code coverage is turned off. However once I try to enable code coverage, I have a failed build/test with 4 classes giving the following error message: Command failed due to signal: Segmentation fault: 11 . 回答1: Here is what worked for me (as all the other suggestions did not work in my case). I was getting a segmentation fault 11 on a particular Swift class when trying to run unit tests with code coverage turned ON. It

Testing autolayout with XCTest

自作多情 提交于 2019-12-10 14:18:48
问题 I'm trying to figure out if there is a way to test the layout of an iOS view in unit tests when using autolayout. Right now I try to simply initialize the view controller, and then check the frames of the views. However, the frame on each view remains origin=(x=0, y=0) size=(width=0, height=0). - (void)setUp { [super setUp]; _viewController = [[AddPlayerViewController alloc] init]; _viewController.view.frame = CGRectMake(0, 0, 320, 460); [_viewController view]; } - (void