xctest

Is it possible to run XCTest tests in an iOS app?

佐手、 提交于 2019-11-29 03:59:13
We have a backend test suite written with XCTest. The suite runs great in Xcode, but for various reasons it would be nice for us if we could also run the suite in an iOS app. Is that possible? I don’t mind writing some glue code for it, but as it is I can’t even import the XCTest framework in a non-testing target: SomeController.swift:2:8: Cannot load underlying module for 'XCTest' Jeremy W. Sherman It is possible! The key is to get a copy of the XCTest framework linking and then use the public XCTest APIs to run your tests. This will give you the same console output you see when running the

XCUIElement - Obtain Image value

天涯浪子 提交于 2019-11-29 03:21:37
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. 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 image view, button, etc. Similarly, there is no way to access other properties of views that might be of

How do I run xctest from the command-line with Xcode 5?

北战南征 提交于 2019-11-29 02:55:11
问题 I found a command-line tool called "xctest" that apparently can run the unit tests in your project. This executable lives here: /Applications/Xcode.app/Contents/Developer/usr/bin/xctest When I try to run this executable on my xctest bundle, I'm using: $ ./xctest /Users/myusername/Library/Developer/Xcode/DerivedData/MyApp-abcdefghijklmnop/Build/Products/Debug/MyAppTests.xctest However, I get the following output: Test Suite '(null)' started at 2013-11-14 21:16:45 +0000 Test Suite '(null)'

addUIInterruptionMonitor(withDescription:handler:) not working on iOS 10 or 9

烈酒焚心 提交于 2019-11-29 02:30:13
问题 The following tests works fine on iOS 11. It dismisses the alert asking permissions to use the locations services and then zooms in in the map. On iOS 10 or 9, it does none of this and the test still succeeds func testExample() { let app = XCUIApplication() var handled = false var appeared = false let token = addUIInterruptionMonitor(withDescription: "Location") { (alert) -> Bool in appeared = true let allow = alert.buttons["Allow"] if allow.exists { allow.tap() handled = true return true }

Testing assertion in Swift

烈酒焚心 提交于 2019-11-29 02:28:29
问题 I'm writing unit tests for a method that has an assertion. The Swift Language guide recommends using assertions for "invalid conditions": Assertions cause your app to terminate and are not a substitute for designing your code in such a way that invalid conditions are unlikely to arise. Nonetheless, in situations where invalid conditions are possible, an assertion is an effective way to ensure that such conditions are highlighted and noticed during development, before your app is published. I

How can I run XCTest for a swift application from the command line?

自闭症网瘾萝莉.ら 提交于 2019-11-29 02:14:40
问题 I want to test drive some Swift examples using XCTest from the command line if possible. import XCTest class LeapTest : XCTestCase { func testVanillaLeapYear() { let year = Year(calendarYear: 1996) XCTAssertTrue(year.isLeapYear); } } I'd love to run it from the command line. I already set Xcode to use the developer tools in the beta: sudo xcode-select -s /Applications/Xcode6-Beta.app/Contents/Developer/ If I naively try and run it it goes like this $ xcrun swift LeapTest.swift LeapTest.swift

UI Test Case not show code coverage

孤街浪徒 提交于 2019-11-29 01:46:08
问题 I have some tests written using XCTestCase classes and I want to calculate code coverage. For the regular test it is shown nicely in my bot, but for UI Tests is always 0%. The simplest test: import XCTest class FAQUITests: XCTestCase { let app = XCUIApplication() override func setUp() { super.setUp() app.launch() } func openFaqView() { app.navigationBars["NavigationBar"].buttons["FAQ"].tap() } func testFaq() { openFaqView() app.tables.cells.elementBoundByIndex(0).tap() } } And this surely

How to run one-time setup code before executing any XCTest

ε祈祈猫儿з 提交于 2019-11-29 01:32:24
问题 I have the following problem. I want to execute a piece of code before all test classes are executed. For instance: I don't want my game to use the SoundEngine singleton during executing, but the SilentSoundEngine. I would like to activate the SilentSoundEngine one time not in all tests. All my tests look like this: class TestBasketExcercise : XCTestCase { override func setUp() { SilentSoundEngine.activate () // SoundEngine is a singleton } // The tests } -Edit- Most of the answers are

XCTAssertEqual fails to compare two string values?

房东的猫 提交于 2019-11-29 01:21:03
问题 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

Can't import main swift classes into test target?

大城市里の小女人 提交于 2019-11-29 00:28:53
问题 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