6 Replies
      Latest reply on Jun 9, 2016 2:23 AM by ratkins
      mcskwayrd Level 1 Level 1 (0 points)

        I'm new to Swift development, just got the Xcode 7 beta 5 last week, and I don't understand what the Tests and UITests auto-created build targets are about, all I know is they always fail in runtime. 

         

        Question(s):

        1. Is this to be expected?
        2. Is there something I really need to worry about and/or fix?
        3. Will this affect my eligibility for App Store distribution?

         

        (I'd noticed that these Products were always in red for the app I've started working on, so I tried pressing Command-U to build them, and in the middle of the simulator run, it failed with an ancaught exception.  ...Ok, well, I'd moved some things around and perhaps that broke something.)

         

        I just now created a fresh new  project in Swift and selected single-view application, and tried to build this "blank" app for testing.   Same thing happens:

        It crashes at the call to XCUIApplication().launch() on line 21 of the ProjectNameUITests.swift file.

         

        The crash log is as follows....

         

        2015-08-21 17:25:53.355 XCTRunner[23578:764977] Running tests...
        2015-08-21 17:25:53.356 XCTRunner[23578:764977] Looking for test bundles in /Users/myusername/Library/Developer/CoreSimulator/Devices/E4AD0BED-5385-4101-896D-961ADDD81217/data/Containers/Bundle/Application/405DDB28-80C8-40EB-8A82-716F140FD13C/ProjectNameUITests-Runner.app/PlugIns
        2015-08-21 17:25:53.356 XCTRunner[23578:764977] Found test bundle at /Users/myusername/Library/Developer/CoreSimulator/Devices/E4AD0BED-5385-4101-896D-961ADDD81217/data/Containers/Bundle/Application/405DDB28-80C8-40EB-8A82-716F140FD13C/ProjectNameUITests-Runner.app/PlugIns/ProjectNameUITests.xctest
        2015-08-21 17:25:53.357 XCTRunner[23578:764977] Looking for configurations in /Users/myusername/Library/Developer/CoreSimulator/Devices/E4AD0BED-5385-4101-896D-961ADDD81217/data/Containers/Bundle/Application/405DDB28-80C8-40EB-8A82-716F140FD13C/ProjectNameUITests-Runner.app/PlugIns/ProjectNameUITests.xctest
        2015-08-21 17:25:53.375 XCTRunner[23578:764977] Found configuration <XCTestConfiguration: 0x7fcf94913130>
                              testBundleURL:file:///Users/myusername/Library/Developer/Xcode/DerivedData/ProjectName-dwclcbyapxiiksauaxkvomftkqug/Build/Products/Debug-iphonesimulator/ProjectNameUITests-Runner.app/PlugIns/ProjectNameUITests.xctest
                          productModuleName:ProjectNameUITests
                                testsToSkip:(null)
                                 testsToRun:(null)
                         reportResultsToIDE:YES
                          sessionIdentifier:<__NSConcreteUUID 0x7fcf9490ef30> 99C63FB1-6ACF-4226-822D-9856B34B6638
                 pathToXcodeReportingSocket:(null)
                  disablePerformanceMetrics:no
            treatMissingBaselinesAsFailures:no
                            baselineFileURL:(null)
                      targetApplicationPath:/Users/myusername/Library/Developer/Xcode/DerivedData/ProjectName-dwclcbyapxiiksauaxkvomftkqug/Build/Products/Debug-iphonesimulator/ProjectName.app
                  targetApplicationBundleID:com.mycompany.com.ProjectName
                           reportActivities:no
        Test Suite 'All tests' started at 2015-08-21 17:25:53.901
        Test Suite 'ProjectNameUITests.xctest' started at 2015-08-21 17:25:53.902
        Test Suite 'ProjectNameUITests' started at 2015-08-21 17:25:53.903
        Test Case '-[ProjectNameUITests.ProjectNameUITests testExample]' started.
            t =     0.00s     Start Test
            t =     0.00s     Set Up
            t =     0.03s         Launch com.mycompany.com.ProjectName
            t =     2.70s             Assertion Failure: UI Testing Failure - Failed to receive completion for <XCDeviceEvent:0x7fcf92c09320 page 12 usage 64 duration 0.01s within 2.5s
        /Users/myusername/exercises/iOS/ProjectName/ProjectNameUITests/ProjectNameUITests.swift:21: error: -[ProjectNameUITests.ProjectNameUITests testExample] : UI Testing Failure - Failed to receive completion for <XCDeviceEvent:0x7fcf92c09320 page 12 usage 64 duration 0.01s within 2.5s
        2015-08-21 17:25:56.636 XCTRunner[23578:764977] *** Terminating app due to uncaught exception '_XCTestCaseInterruptionException', reason: 'Interrupting test'
        *** First throw call stack:
        (
            0   CoreFoundation                      0x000000010c5049b5 __exceptionPreprocess + 165
            1   libobjc.A.dylib                     0x000000010bf7cdeb objc_exception_throw + 48
            2   CoreFoundation                      0x000000010c5048ed +[NSException raise:format:] + 205
            3   XCTest                              0x000000010ba44b4d -[XCTestCase _dequeueFailures] + 560
            4   XCTest                              0x000000010ba44e29 -[XCTestCase _enqueueFailureWithDescription:inFile:atLine:expected:] + 576
            5   XCTest                              0x000000010ba4c5b8 _XCTFailureHandler + 1112
            6   XCTest                              0x000000010ba43fcd _XCTFailInCurrentTest + 512
            7   XCTest                              0x000000010ba60da3 -[XCUIDevice _dispatchEventWithPage:usage:duration:] + 790
            8   XCTest                              0x000000010ba52a35 -[XCAXClient_iOS init] + 94
            9   XCTest                              0x000000010ba529ce __30+[XCAXClient_iOS sharedClient]_block_invoke + 24
            10  libdispatch.dylib                   0x000000010e73e4c7 _dispatch_client_callout + 8
            11  libdispatch.dylib                   0x000000010e72bd2f dispatch_once_f + 76
            12  XCTest                              0x000000010ba529b4 +[XCAXClient_iOS sharedClient] + 42
            13  XCTest                              0x000000010ba622f9 __37-[XCUIApplication _launchUsingXcode:]_block_invoke + 50
            14  XCTest                              0x000000010ba486c7 -[XCTestCase startActivityWithTitle:block:] + 305
            15  XCTest                              0x000000010ba622b8 -[XCUIApplication _launchUsingXcode:] + 309
            16  ProjectNameUITests                    0x00000001188ef809 _TFC16ProjectNameUITests16ProjectNameUITests5setUpfS0_FT_T_ + 153
            17  ProjectNameUITests                    0x00000001188ef892 _TToFC16ProjectNameUITests16ProjectNameUITests5setUpfS0_FT_T_ + 34
            18  XCTest                              0x000000010ba486c7 -[XCTestCase startActivityWithTitle:block:] + 305
            19  XCTest                              0x000000010ba45083 __24-[XCTestCase invokeTest]_block_invoke_2 + 118
            20  XCTest                              0x000000010ba72824 -[XCTestContext performInScope:] + 184
            21  XCTest                              0x000000010ba44ffc -[XCTestCase invokeTest] + 169
            22  XCTest                              0x000000010ba45497 -[XCTestCase performTest:] + 443
            23  XCTest                              0x000000010ba4315d -[XCTestSuite performTest:] + 377
            24  XCTest                              0x000000010ba4315d -[XCTestSuite performTest:] + 377
            25  XCTest                              0x000000010ba4315d -[XCTestSuite performTest:] + 377
            26  XCTest                              0x000000010ba3098d __25-[XCTestDriver _runSuite]_block_invoke + 51
            27  XCTest                              0x000000010ba50b53 -[XCTestObservationCenter _observeTestExecutionForBlock:] + 615
            28  XCTest                              0x000000010ba308d9 -[XCTestDriver _runSuite] + 408
            29  XCTest                              0x000000010ba31638 -[XCTestDriver _checkForTestManager] + 263
            30  XCTest                              0x000000010ba73b4e _XCTestMain + 628
            31  libdispatch.dylib                   0x000000010e722ea9 _dispatch_call_block_and_release + 12
            32  libdispatch.dylib                   0x000000010e73e4c7 _dispatch_client_callout + 8
            33  libdispatch.dylib                   0x000000010e72907d _dispatch_main_queue_callback_4CF + 714
            34  CoreFoundation                      0x000000010c464e69 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
            35  CoreFoundation                      0x000000010c4263b9 __CFRunLoopRun + 2073
            36  CoreFoundation                      0x000000010c425918 CFRunLoopRunSpecific + 488
            37  GraphicsServices                    0x000000010df68ad2 GSEventRunModal + 161
            38  UIKit                               0x000000010c8b299e UIApplicationMain + 171
            39  XCTRunner                           0x000000010b9bb6bf XCTRunner + 5823
            40  libdyld.dylib                       0x000000010e76e92d start + 1
        )
        libc++abi.dylib: terminating with uncaught exception of type _XCTestCaseInterruptionException
        (lldb)
        

        ...and the two Products are still shown in red on the left.

         

        So...this is over my head given my beginner status.  I'm not sure what I'm doing wrong, I'm working with the program "fresh out of the box" and not trying anything fancy.

        Any feedback would be appreciated.  Thanks

        • Re: Swift: 'Stock' UITest fails: uncaught exception in XCTest. ??
          mgrebenets Level 1 Level 1 (0 points)

          Same story for me, only I have an exsiting project to deal with and the error message is slightly different:

           

          UI Testing Failure - Failed to background test runner.

           

          What's strange, is that I have no issues with running recording, it's only when it comes to running the tests I get this error.

          I have tried running a test action on the UI Testing scheme as well as test action on the main app target. Got the same results when running from command line and tried all possible iOS 9.0 simulators. Here's my full log:

           

          
              t =    10.07s             Assertion Failure: UI Testing Failure - Failed to background test runner.
          /Users/maksym.grebenets/Projects/ffx/ci-workspace/mobile-apm-alfred/AlfredAcceptanceTests/AlfredAcceptanceTests.swift:22: error: -[Alfred.AlfredAcceptanceTests testExample] : UI Testing Failure - Failed to background test runner.
          2015-08-31 15:29:01.260 AFR-dev[20969:1615111] *** Terminating app due to uncaught exception '_XCTestCaseInterruptionException', reason: 'Interrupting test'
          *** First throw call stack:
          (
            0   CoreFoundation                      0x00000001101be9b5 __exceptionPreprocess + 165
            1   libobjc.A.dylib                     0x000000010f7dcdeb objc_exception_throw + 48
            2   CoreFoundation                      0x00000001101be8ed +[NSException raise:format:] + 205
            3   XCTest                              0x000000011c11c8b9 -[XCTestCase _dequeueFailures] + 560
            4   XCTest                              0x000000011c11cb95 -[XCTestCase _enqueueFailureWithDescription:inFile:atLine:expected:] + 576
            5   XCTest                              0x000000011c124340 _XCTFailureHandler + 1112
            6   XCTest                              0x000000011c11bd39 _XCTFailInCurrentTest + 512
            7   XCTest                              0x000000011c12aa74 -[XCAXClient_iOS init] + 789
            8   XCTest                              0x000000011c12a756 __30+[XCAXClient_iOS sharedClient]_block_invoke + 24
            9   libdispatch.dylib                   0x00000001119654c7 _dispatch_client_callout + 8
            10  libdispatch.dylib                   0x0000000111952d2f dispatch_once_f + 76
            11  XCTest                              0x000000011c12a73c +[XCAXClient_iOS sharedClient] + 42
            12  XCTest                              0x000000011c13abe6 __37-[XCUIApplication _launchUsingXcode:]_block_invoke + 50
            13  XCTest                              0x000000011c120443 -[XCTestCase startActivityWithTitle:block:] + 305
            14  XCTest                              0x000000011c13aba5 -[XCUIApplication _launchUsingXcode:] + 309
            15  AlfredAcceptanceTests               0x0000000123e76449 _TFC6Alfred21AlfredAcceptanceTests5setUpfS0_FT_T_ + 153
            16  AlfredAcceptanceTests               0x0000000123e764d2 _TToFC6Alfred21AlfredAcceptanceTests5setUpfS0_FT_T_ + 34
            17  XCTest                              0x000000011c120443 -[XCTestCase startActivityWithTitle:block:] + 305
            18  XCTest                              0x000000011c11cdef __24-[XCTestCase invokeTest]_block_invoke_2 + 118
            19  XCTest                              0x000000011c14c4a0 -[XCTestContext performInScope:] + 184
            20  XCTest                              0x000000011c11cd68 -[XCTestCase invokeTest] + 169
            21  XCTest                              0x000000011c11d203 -[XCTestCase performTest:] + 443
            22  XCTest                              0x000000011c11aec9 -[XCTestSuite performTest:] + 377
            23  XCTest                              0x000000011c11aec9 -[XCTestSuite performTest:] + 377
            24  XCTest                              0x000000011c11aec9 -[XCTestSuite performTest:] + 377
            25  XCTest                              0x000000011c1086d2 __25-[XCTestDriver _runSuite]_block_invoke + 51
            26  XCTest                              0x000000011c1288db -[XCTestObservationCenter _observeTestExecutionForBlock:] + 615
            27  XCTest                              0x000000011c10861e -[XCTestDriver _runSuite] + 408
            28  XCTest                              0x000000011c10937d -[XCTestDriver _checkForTestManager] + 263
            29  XCTest                              0x000000011c14d801 _XCTestMain + 628
            30  CoreFoundation                      0x00000001100eab0c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
            31  CoreFoundation                      0x00000001100e0795 __CFRunLoopDoBlocks + 341
            32  CoreFoundation                      0x00000001100dfef2 __CFRunLoopRun + 850
            33  CoreFoundation                      0x00000001100df918 CFRunLoopRunSpecific + 488
            34  GraphicsServices                    0x000000011291aad2 GSEventRunModal + 161
            35  UIKit                               0x000000010c9c699e UIApplicationMain + 171
            36  AFR-dev                             0x000000010b3089ff main + 111
            37  libdyld.dylib                       0x000000011199592d start + 1
          )
          libc++abi.dylib: terminating with uncaught exception of type _XCTestCaseInterruptionException
          
          • Re: Swift: 'Stock' UITest fails: uncaught exception in XCTest. ??
            Dahu557 Level 1 Level 1 (0 points)

            I have experienced the same crash like you exactly at the same line with the same crash log.

             

            During testing I noticed that this crash might be related to the app launching handling. Apple seems to have set a timeout for the testing instance and if the instance didn't get response from your app before the timeout, the instance will be terminated and the app crashes at the launch() position.

             

            Because I have tested the same copy of my app on two different machines, I was able to notice the difference.

             

            One maschine runs a 5400rpm HDD and it takes relatively long time to launch a new iPhone Simulator, and I noticed that if the running target has been changed (e.g. switching from iPhone 6 to iPhone 5s), it always takes >10s to launch the Simulator and the app. After the app launching and the UI testing starts to run, then the app crashes. Sometimes I can avoid entering this problem by starting the UI test again without changing the target settings. If the Simulator didn't reload again, and the app was able to get launched fast, and this issue has gone.


            On the other hand, the machine with a SSD setup is able to laucnhes a completely new Simulator in a very short time (<0.5 s), and I have never encoutered this issue on this machine (with the same project setup).


            Hope this info helps. I'm setting up an automated UI testing enviorment for all models on the slow maschine so I also need to get rid of this problem. As long as we can figure out a way to change the default timeout setting, we might be able to solve the problem.


            Best regards,

            Dahu557

            • Re: Swift: 'Stock' UITest fails: uncaught exception in XCTest. ??
              ratkins Level 1 Level 1 (0 points)

              Does your app perform notifications, or request location access perchance?

               

              I'm having this issue when I run my tests locally on a fresh simulator. Tests prior to the UI tests register for notifications and the "Will you let this app send notifications?" system alert pops up. If I dismiss it in the simulator manually, the tests then run through fine.