xctest

XCUIElement - Obtain Image value

别等时光非礼了梦想. 提交于 2019-11-27 17:42:50
问题 I have an variable that's of type .Image and class XCUIElement . Something like this: var image = app.descendantsMatchingType(.Image).elementAtIndex(0) Is there a way I can extract the actual image so I can compare it to another image? I've tried caling the value method, but it returns a string. Casting it to a UIImage always fails. 回答1: I have had a conversation about this with the Apple Developer Tools evangelist recently. There is currently no way of accessing the actual image from an

iOS XCUITests access element by accessibility

自作多情 提交于 2019-11-27 17:41:39
问题 How do I assert a button exists by his accessibilityLabel or identifier? func testExitsButton() { XCTAssertTrue(app.windows.containing(.button, identifier: "Button Text").element.exists) XCTAssertTrue(app.buttons["Button Text"].exists) XCTAssertTrue(app.buttons["test"].exists) <- I want this, instead of accessing the text property I want by specific id, maybe the text property override the accessibilityLabel? } 回答1: Set an accessibility identifier in your application code, and then search for

Xcode 5 says tests failed but shows green checkmarks

别等时光非礼了梦想. 提交于 2019-11-27 14:18:52
问题 I have written a few unit tests in the new XCTest framework of Xcode 5. The tests seem to pass successfully most of the time, but I've come across a strange behaviour where if I run the tests enough times consecutively, eventually I'll get a 'test failed' message and the console will show Program ended with exit code 0 , but there are green checkmarks beside all the tests. What's going wrong here? 回答1: This is definitely a bug. Submit a report via https://bugreport.apple.com/ feel free to

What is the purpose of XCTestCase's setUp method?

两盒软妹~` 提交于 2019-11-27 13:27:49
问题 Per the comment within the default template for XCTestCase regarding setUp : Put setup code here; it will be run once, before the first test case. However, in XCTestCase.h , the comment above setUp states differently: Setup method called before the invocation of each test method in the class. To confirm the actual behavior, I put an NSLog within setUp to count how many times it was called: static int count = 0; - (void)setUp { [super setUp]; count++; NSLog(@"Call Count = %d", count); } This

How to speed up UI test cases in Xcode?

旧时模样 提交于 2019-11-27 13:01:00
问题 Since Xcode 7 we have a nice API for UI testing. Mostly I'm satisfied with it. The only concern is related to the speed. In the beginning an ordinary UI test case (about 15 actions) ran approximately 25 seconds . Then I mocked networking completely. Now it takes 20 seconds . Considering the fact that the time is taken only by animations and a launch time (1 second or even less), I assume, there must be a way to speed it up. 回答1: Try setting this property when your UI tests run: UIApplication

How do I unit test HTTP request and response using NSURLSession in iOS 7.1?

坚强是说给别人听的谎言 提交于 2019-11-27 10:53:43
问题 I'd like to know how to "unit test" HTTP requests and responses using NSURLSession. Right now, my completion block code does not get called when running as a unit test. However, when the same code is executed from within the AppDelegate (didFinishWithLaunchingOptions), the code inside the completion block is called. As suggested in this thread, NSURLSessionDataTask dataTaskWithURL completion handler not getting called, the use of semaphores and/or dispatch_group is needed "to make sure the

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

独自空忆成欢 提交于 2019-11-27 10:17:40
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 application is built first (as a dependancy) then the tests. The linker then figures it out what the

How can I get XCTest to wait for async calls in setUp before tests are run?

蹲街弑〆低调 提交于 2019-11-27 10:01:44
问题 I'm writing integration tests in Xcode 6 to go alongside my unit and functional tests. XCTest has a setUp() method that gets called before every test. Great! It also has XCTestException's which let me write async tests. Also great! However, I would like to populate my test database with test data before every test and setUp just starts executing tests before the async database call is done. Is there a way to have setUp wait until my database is ready before it runs tests? Here's an example of

Cannot load underlying module for XCTest

霸气de小男生 提交于 2019-11-27 09:54:10
问题 I'm working in swift on Xcode and by default it creates a test file that references XCTest. When I set the target membership to my main project it causes this error Cannot load underlying module for XCTest If this target membership is not set the tests runs properly and everything works fine. PS: I'm new to swift and it's probably a dumb question (please enlighten me) 回答1: The main project does not link with the XCUnit framework. You should create a separate testing target for your project,

Xcode Unit Testing with Cocoapods

允我心安 提交于 2019-11-27 09:30:51
问题 I've been banging my head against a wall with this for the last few days but despite multiple Google/SO/Github searches I can't find a resolution to the issues I'm having! All I'm trying to do is create some unit tests for my app which makes use of Firebase pods. I'm using Xcode 7.3.1 & Cocoapods 1.0.1. Update: Issue remains with Xcode 8.0 With this podfile: platform :ios, '9.0' use_frameworks! inhibit_all_warnings! target 'MyApp' do pod 'Firebase' pod 'Firebase/Auth' pod 'Firebase/Database'