xctest

iOS UI Testing On an Isolated View

牧云@^-^@ 提交于 2019-12-17 21:46:05
问题 I'm trying to incorporate UI tests in my iOS project, but one thing that continues to hold me up is the fact that it seems all of the tests you write must start from the beginning of the app and work their way through. For example, if I want to test a view that is behind a login screen, my tests must first run on the login screen, enter a username/password, click login, then go to the view I want to test. Ideally, the tests for the login view and the next one would be completely isolated. Is

Unit Test fatalError in Swift

拜拜、爱过 提交于 2019-12-17 17:48:17
问题 How to implement unit test for a fatalError code path in Swift? For example, I've the following swift code func divide(x: Float, by y: Float) -> Float { guard y != 0 else { fatalError("Zero division") } return x / y } I want to unit test the case when y = 0. Note, I want to use fatalError not any other assertion function. 回答1: Nimble ("A Matcher Framework for Swift and Objective-C") got your back : Swift Assertions If you're using Swift, you can use the throwAssertion matcher to check if an

How to select a picker view item in an iOS UI test in Xcode?

孤者浪人 提交于 2019-12-17 16:26:49
问题 I have a picker view with few items: "Red", "Green", "Yellow", "Black". In my UI test I need to select a specific item "Green" from it. I am using the XCTest UI testing APIs that were intruduced with Xcode 7. What I managed to do so far is to swipe the whole picker view up in the unit test. It is not ideal because it always changes the picker view to the bottom item (when swiping up). let app = XCUIApplication() app.launch() app.pickers.elementAtIndex(0).swipeUp() XCTAssert(app.staticTexts[

When do app sources need to be included in test targets?

雨燕双飞 提交于 2019-12-17 10:10:15
问题 In a new project I have this simple test #import <XCTest/XCTest.h> #import "ViewController.h" @interface ViewControllerTests : XCTestCase @end @implementation ViewControllerTests - (void)testExample { // Using a class that is not in the test target. ViewController * viewController = [[ViewController alloc] init]; XCTAssertNotNil(viewController, @""); } @end ViewController.h is not part of the test target yet this compiles and runs the tests with no issues. I think this is because the

Is there a way to reset the app between tests in Swift XCTest UI?

不问归期 提交于 2019-12-17 08:05:19
问题 Is there an API call within XCTest that I can put into the setUP() or tearDown() to reset the app between tests? I looked in the dot syntax of XCUIApplication and all I saw was the .launch() OR is there a way to call a shell script in Swift? I could then call xcrun in-between test methods to reset the simulator. 回答1: You can add a "Run Script" phase to build phases in your test target to uninstall the app before running unit tests against it, unfortunately this is not between test cases,

Is there a way to reset the app between tests in Swift XCTest UI?

早过忘川 提交于 2019-12-17 08:03:15
问题 Is there an API call within XCTest that I can put into the setUP() or tearDown() to reset the app between tests? I looked in the dot syntax of XCUIApplication and all I saw was the .launch() OR is there a way to call a shell script in Swift? I could then call xcrun in-between test methods to reset the simulator. 回答1: You can add a "Run Script" phase to build phases in your test target to uninstall the app before running unit tests against it, unfortunately this is not between test cases,

XCTest and asynchronous testing in Xcode 6

廉价感情. 提交于 2019-12-17 07:20:42
问题 So Apple said in the release note of Xcode 6 that we can now do asynchronous testing directly with XCTest. Anyone knows how to do it using Xcode 6 Beta 3 (Using objective-C or Swift)? I don't want the known semaphore method, but the new Apple way. I searched into the released note and more but I found nothing. The XCTest header is not very explicit either. 回答1: Obj-C example: - (void)testAsyncMethod { //Expectation XCTestExpectation *expectation = [self expectationWithDescription:@"Testing

Testing a Timer in Xcode with XCTest

馋奶兔 提交于 2019-12-14 01:30:04
问题 I have a function that does not need to be called any more than every 10 secs. Every time I invoke the function, I reset the timer to 10 secs. class MyClass { var timer:Timer? func resetTimer() { self.timer?.invalidate() self.timer = Timer.scheduledTimer(withTimeInterval: 10.0, repeats: false) { (timer) -> Void in self.performAction() } } func performAction() { // perform action, then self.resetTimer() } } I would like to test that calling performAction() manually resets the timer to 10 secs,

How do I install the XCUITest runner app and ipa on a real device and get the results?

醉酒当歌 提交于 2019-12-13 12:14:21
问题 How do I install the XCUITest runner app and ipa on a real device and get the results? I have a runner.app that was generated by building it for testing, and a deployed/signed .ipa. Now what I would like to happen is to have it installed on a real device, execute it, and get the device log. 回答1: Edited with answer... It is possible to achieve this. In order to build an ipa of the UI Testing app bundle you can follow these steps: Open your project containing in Xcode. Select the device you'd

How to add tap action for button in “Unit Testing” and show Alert

独自空忆成欢 提交于 2019-12-13 08:03:40
问题 I am trying to write a unit test case for my Login Form, in this if Username and Password empty then we click login button it will show alert, i want to write testcases for this scenario, for me button action not working and alert not showing with unit testing , i am searching for solution long time any one could help..Thanks! 回答1: First, let me say that rather than an alert, you might consider keeping the Log In button disabled until the User Name and Password are non-empty. But to answer