xctest

Use of Unit Test in Xcode 5

元气小坏坏 提交于 2019-12-03 01:25:46
I am writing my first bigger iOS project and I want to use as much of Xcode 5 as possible. Now I want to use testing but I have never done it before. My project uses come Views and dynamic `TableViews. How could I implement the test in the code, so that it makes sense? Please start by watching WWDC '13 session 409 - Testing in Xcode 5 . It's a very good starting point. Next, if you're not feeling confident of your approach to unit testing, I'd recommend reading "Test-Driven iOS Development" by Graham Lee . For now, remember that a unit test tests single "unit" of functionality and does not

failing a XCTestCase with assert without the test continuing to run but without stopping other tests

我怕爱的太早我们不能终老 提交于 2019-12-02 22:32:23
I'm trying to test my application using the XCTest framework. I want my single test case to fail if some logical condition holds (using an assertion). I don't want the rest of the code in the test case to run, because this might lead to problems (access to null pointers, for example) I also want the rest of the test case to run normally, and just the failed test to be marked as failed. I've noticed XCTestCase has a property called continueAfterFailure. However, setting it to YES caused the failed test to continue executing lines after the assertion, and setting it to NO caused the rest of the

Error loading XCTest, no suitable image found.

不打扰是莪最后的温柔 提交于 2019-12-02 22:03:53
I have recently updated my Xcode and started having this error. 2014-11-03 15:03:54.222 App[13141:60b] Error loading /private/var/mobile/Applications/677127BD-5230-4D5F-B70E-AF728439D34B/tmp/AppTests.xctest/AppTests: dlopen(/private/var/mobile/Applications/677127BD-5230-4D5F-B70E-AF728439D34B/tmp/AppTests.xctest/AppTests, 262): no suitable image found. Did find: /private/var/mobile/Applications/677127BD-5230-4D5F-B70E-AF728439D34B/tmp/AppTests.xctest/AppTests: code signature invalid for '/private/var/mobile/Applications/677127BD-5230-4D5F-B70E-AF728439D34B/tmp/AppTests.xctest/AppTests'

XCTests Failing on Physical Device: “Canceling tests due to timeout …”

ぃ、小莉子 提交于 2019-12-02 19:22:43
XCTests are failing with the message: *** Canceling tests due to timeout in Waiting for test process to check in... This just started coming up in the last few days. I'm using Xcode 7.3.1, with iOS 9.3.2 running on an iPhone 6. My app is written mostly in Swift. I've seen some similar posts: Unable to run XCTests on iOS device iOS tests will not run on simulator when using Jenkins through JNLP Those other posts talk about this issue as arising with code signing. Code signing does not seem to be my problem-- I've looked at the KeyChain Access utility and don't see any relevant expired

XCTestExpectation: how to avoid calling the fulfill method after the wait context has ended?

空扰寡人 提交于 2019-12-02 18:10:57
I’m using the new asynchronous testing capabilities of Xcode 6. Everything works fine when the asynchronous task ends before the timeout. But if the task takes longer than the timeout, things get more complicated. Here is how I’m doing my tests: @interface AsyncTestCase : XCTestCase @end @implementation AsyncTestCase // The asynchronous task would obviously be more complex in a real world scenario. - (void) startAsynchronousTaskWithDuration:(NSTimeInterval)duration completionHandler:(void (^)(id result, NSError *error))completionHandler { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64

How to let the app know if its running Unit tests in a pure Swift project?

半腔热情 提交于 2019-12-02 17:14:05
One annoying thing when running tests in XCode 6.1 is that the entire app has to run and launch its storyboard and root viewController. In my app this runs some server calls that fetches API data. However, I don't want the app to do this when running its tests. With preprocessor macros gone, whats the best for my project to be aware that it was launched running tests and not an ordinary launch? I run them normally with CMD+U and on a bot. Pseudo code would be: // Appdelegate.swift if runningTests() { return } else { // do ordinary api calls } Eivind Rannem Bøhler Instead of checking if the

Unable to run XCTests on iOS device

怎甘沉沦 提交于 2019-12-02 16:04:36
问题 I've recently noticed that I can't run tests on my iOS devices. I've tried on both an iPhone 5 and an iPhone 6. Both fail with an error like this: 2015-07-13 12:32:26.930 MyApp[1316:735999] Error loading /private/var/mobile/Containers/Data/Application/B23BED3F-5D59-4727-9AAB-1155A3F3A8F2/tmp/MyApp Tests.xctest/MyApp Tests: dlopen(/private/var/mobile/Containers/Data/Application/B23BED3F-5D59-4727-9AAB-1155A3F3A8F2/tmp/MyApp Tests.xctest/MyApp Tests, 262): no suitable image found. Did find:

XCTest UI tests: can not find collectionView within a table cell

懵懂的女人 提交于 2019-12-02 08:13:27
There is a cell contains a Collection View. I have set the cells within a Collection View using cell.accessibilityLabel = @"daren_shangjia_0001_add_new_photo_album"; and then in XCTest, I do print(app.debugDescription); I didn't see the accessibilityLabel that I have provided. Element subtree: →Application 0x608000367200: {{0.0, 0.0}, {414.0, 736.0}}, label: '纳豆行' Window 0x608000365e80: Main Window, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000365880: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000365b80: traits: 8589934592, {{0.0, 0.0}, {414.0, 736.0}} Other 0x608000365700:

How to call XCTest test case functions by order in Xcode 8?

你。 提交于 2019-12-02 05:27:46
问题 XCTest test functions was called in alphabetical order (before Xcode 8). With Xcode 8, I can not assume in which order the test cases are called by the system. Can someone throw light on it? 回答1: Tests within a class are run in a random order in Xcode 8. This encourages tests to be independent and repeatable . I'm assuming that you want to run your tests in a specific order because they "chain" off of each other. For example, test_A logs a fake user in and test_B adds an item to the shopping

Why, when I am testing that a method throws an exception and the method throw an exception, does the test stop?

自作多情 提交于 2019-12-02 04:13:53
I have a unit test that tests if method throws an exception when condition is present, and method does throws exception as expected. - (void)testMethodThrowsWhenConditionIsPresent { XCTAssertThrows([Foo methodWithCondition: condition], @"Condition is true, method should throw exception"); } Here is the exception source: - (void)methodWithCondition:(someType)condition { if (condition) { [NSException raise: @"condition is true!" format: @"condition is true!"]; } } Why does the test stop at the line the exception is thrown? The test does not go on, it stops at that line, when I expect it to