xctest

How to test UIImageView elements in iOS XCTest?

≡放荡痞女 提交于 2019-11-30 04:15:18
问题 I'm trying to test my UIs using XCTest UI testing, and having troubles of testing UIImageViewsI have in my app (hit tests, presence etc). In the list of the XCUIElementType there is no such type, and when I look at the children of the superview my UIImageViews are not listed there for some reason eventhough I can see them on screen and in the UI inspector in the Xcode. Has anyone had this kind of problem? 回答1: Assert the presence of an image by its accessibility label. Production Code let

XCTAssertEqual fails to compare two string values?

北慕城南 提交于 2019-11-30 04:09:20
I added a simple unit test to test my string extension. But it fails. What I am I doing wrong here? From what I know XCTAssertEqual is testing value and not the object itself? The third line btw, says the string are equal, but XCTAssertEqual says they're not. - (void) testInitialsFromFullname { NSString *firstNickName = @"Mike Kain"; NSString *expectedResult = @"MK"; NSLog(@"Equal:%@", [[firstNickName initialsFromString] isEqualToString:expectedResult] ? @"YES" : @"NO"); XCTAssertEqual(expectedResult, [firstNickName initialsFromString], @"Strings are not equal %@ %@", expectedResult,

Can't import main swift classes into test target?

本秂侑毒 提交于 2019-11-30 03:52:50
I am trying to test the classes in my iOS app. I am trying to import the target Pickle in my app that has all my classes into my testing target PickleTests by adding import Pickle to the top of my PickleTests.swift testing file, but I keep getting an error. The error I keep receiving is: "Failed to import bridging header (path to bridging header)" (the path to the bridging header is shown in the error, not the parentheses). I have tried setting "Defines module" in my build settings for Pickle target to "Yes", but it still doesn't work. I have also verified in the build settings that it has the

How to test a sendAsynchronousRequest: on XCTest

若如初见. 提交于 2019-11-30 03:49:25
Sorry for the noob question, but I'm trying to test a connection, but I'm not able do verify the return of the request, because the test ends before the completion handler have a chance to execute. To ilustrate: -(void)testConnection { [[Conector sharedInstance] performAsynchronousRequestWithServerRequest:_srvRequest completionHandler:^(RequestAsynchronousStatus finishStatus, NSData *data) { if (finishStatus == RequestAsynchronousOK){ _data = data; NSLog(@"Data OK"); } }]; XCTAssertNotNil(_data, @"Data was nil"); } When I try to assert, _data will always be nil, because the completion handler

XCTest - “Test failed”

故事扮演 提交于 2019-11-30 03:46:43
问题 I'm trying to add tests to a mac app. I'm using XCTest framework. When i run tests (cmd + U) i receive "Test failed" and in console I see : 2013-10-15 13:22:56.354 8tracks Radio[40560:303] Error loading /Users/victor/Library/Developer/Xcode/DerivedData/Musica-dhxbqwburbddtietormguodcwoqt/Build/Products/Test/MusicaTests.octest/Contents/MacOS/MusicaTests: dlopen(/Users/victor/Library/Developer/Xcode/DerivedData/Musica-dhxbqwburbddtietormguodcwoqt/Build/Products/Test/MusicaTests.octest/Contents

Accessing user defined variables passed in from xcodebuild command line

北城以北 提交于 2019-11-30 01:30:34
问题 I am running my xctests using xcodebuild and need to pass in some environment variables . In the example below ACCOUNT_ID and HOST_URL . I tried passing in the variables as both environment variable and accessing them from the test using getenv ("ACCOUNT_ID") xcodebuild -project CalculatorTestClient.xcodeproj -scheme CalculatorTestClient -destination '%s' ACCOUNT_ID=%s HOST_URL=%s test" And passing them in as user defaults and accessing them using [[NSUserDefaults standardUserDefaults]

How do I migrate from SenTestingKit/OCUnit to XCTest?

北城余情 提交于 2019-11-29 22:54:27
I am in the process of migrating my project from Xcode 4.6.3 to Xcode 5.0.2. The project's unit tests were developed with SenTestingKit/OCUnit. Now when I am running the tests in Xcode 5, I get an error from the RunUnitTests script telling me that RunUnitTests is obsolete. Possibly related is this note in the Xcode 5 release notes: SenTestingKit and OCUnit are deprecated. Use the migrator to move to XCTest. Unfortunately, I have not been able to find out more about this mysterious "migrator". Possibly my google-fu is lacking [again], so my main question is: How do I migrate unit tests from

NSURL to file path in test bundle with XCTest

倾然丶 夕夏残阳落幕 提交于 2019-11-29 22:37:16
I am trying to write an iOS app using TDD and the new XCTest framework. One of my methods retrieves a file from the internet (given a NSURL object) and stores it in the user's documents. The signature of the method is similar to: - (void) fetchAndStoreImage:(NSURL *)imageUrl I'm trying to write the test for this method in a way that it doesn't fail if there is no connection to the internet. My approach (taken from a previous question ) is to call the method using a NSURL to an image in the local file system. When a new project with unit tests enabled is created, the Tests directory has a

Is it possible to run XCTest based tests under Instruments in Xcode 5?

喜夏-厌秋 提交于 2019-11-29 21:34:14
Looking at XCTest and Xcode 5 unit testing and not seeing how to run my unit tests under Instruments in Xcode 5... Specifically I'd like to look for leaks during the test (this doesn't have to be automated in this instance, though clearly that'd be useful). Possible? I think this is the easiest way: Set a breakpoint somewhere in your tests (I've been doing it in the setup method) Open a new document in instruments Run the application and make sure it's stopped at a breakpoint From the Target drop down in Instruments choose Attach to Process and scroll down to your process Click on record and

Testing UIWebView with Xcode UI Testing

谁都会走 提交于 2019-11-29 17:51:58
问题 I'm using new Xcode UI Testing from XCTest Framework with the Xcode 7 GM . I've got an app with simple UIWebView (it's just a navigation controller + view controller with web view and button) and I want to check following scenario: Web View loads page www.example.com User taps on button Web View loads some page with URL: www.example2.com I want to check which page is loaded in UIWebView after pressing button. Is this possible with UI Testing right now? Actually I'm getting web view like this: