‘NSInternalInconsistencyException’ when running UITesting with Xcode 7
Asked Answered
G

14

41

Ok, I’ve not been able to run this test in any betas so far. Some of the issues I’ve encountered are here and here

Now, I feel like I’m missing something.

Here’s my progress so far

  1. Enabled “UI testing” option while creating a new project. This, in fact adds a target for me. So I should be good to go - or so I thought. enter image description here
  2. The swift file under UI Testing had already “XCTest” imported and was a subclass of “XCTestCase”.
  3. setup() launches the application XCUIApplication().launch()
  4. And I added the following (by hitting the Record button) enter image description here

And then, I ran this test.

The whole thing fails even before the test is called, right after launching app in setup() with the following

*** Assertion failure in -[XCUIApplication init], /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-8170.3/XCTestFramework/UI Testing/XCUIApplication.m:76 /Users/UserName/Documents/Projects/Testing/UiTesting/UITestingApp/UITestingApp.swift:0: error: -[UITestingApp.UITestingApp testSimpleTap] : failed: caught "NSInternalInconsistencyException", "No target application path specified via test configuration:
testBundleURL:file:///Users/UserName/Library/Developer/CoreSimulator/Devices/E3201DC2-CAD3-48C3-95F5-15E18DCA1836/data/Containers/Bundle/Application/8B33FC59-FC03-41F8-BD21-43D81BA2D355/UITestingApp-Runner.app/PlugIns/UITestingApp.xctest/
productModuleName:(null) testsToSkip:(null) testsToRun:(null) reportResultsToIDE:no sessionIdentifier:<__NSConcreteUUID 0x7f93e146c0b0> F242796B-ED26-4AA7-861A-540D2D93CB8F pathToXcodeReportingSocket:(null) disablePerformanceMetrics:no treatMissingBaselinesAsFailures:no baselineFileURL:(null) targetApplicationPath:(null) targetApplicationBundleID:(null) reportActivities:no

Anyone run into this or has any suggestions on what I might be missing?

Note: I did set the “Target Application” of the UI Testing target to my app

Update: I noticed this is applicable to all beta/final releases of Xcode - updated title accordingly

Glynas answered 28/8, 2015 at 17:20 Comment(3)
I merely tried to initialize XCUIApplication in setUp() method and got the same issue.Dall
I'm getting the same crash with Xcode 7Glynas
I saw many blogs writing about UI test with XCTest but non of sample code work as expected. Why? LoLDall
G
2

After endless tweaking, changed the Location of Derived Data in "Xcode Preferences" from "Legacy" to "Custom" and got it to work!

enter image description here

Glynas answered 18/9, 2015 at 18:44 Comment(2)
Doing this does not fix the issue for me :(Outrelief
I'd downvote here, however as I lose score for doing it I won't do it. This is not the answer.Solidarity
S
57

I had a similar issue and my mistake was trying to use UI testing code in a regular test target. Once I made a new target, starting with "iOS UI Testing Bundle" and copied the code there the error went away. Here's the thread that pointed me in the right direction: https://twitter.com/punksomething/status/609505357132500993 "Yeah, I was trying to use a UI test in a regular test target. Had to create a newly added UI Test target"

Starofbethlehem answered 22/9, 2015 at 0:50 Comment(1)
Yes, I saw that post. I had the correct target to start with. thanksGlynas
E
24

This happened to me when I was trying to add a new class to my unit test target but I've selected UI Test Case Class template instead of Unit Test Case Class template.

Make sure that you always select proper one. Eventhough they are both XCTestCase subclass and you assign them to proper target, it will throw this error when selecting wrong template.

enter image description here

Esophagitis answered 9/6, 2016 at 12:6 Comment(4)
Aha! This answer is really helpful, this is one of those cases where you could look all day and find no fix because just by looking at the file there is no showing that anything is wrong.Wolbrom
I literally bumped into the same issue. Comparing the templates was a good hint. Thank you.Monocoque
You save my ass! thks!Safier
I wish this worked for me. I've tried both and still get the same issue with UIApplication.Buddybuderus
C
6

I got this after renaming my target. The solution was to set the 'Target Application' to 'None' in my UITest target and hit build. After this I set 'None' back my app and the error resolved. I think it's highly possible that the renaming messed up the ui test target's 'Target Application' settings.

Commonage answered 20/6, 2016 at 13:57 Comment(2)
Thanks a lot! I got the same problem after renaming whole project.Centralize
I had to set the 'Target Application' to 'None' and hit build. Then I had to set the 'Target Application't back to my project. Thx!Cleavage
T
4

I had this exact problem. I think the issue stemmed from renaming a target along the way. None of the fixes here helped me with my issue. Since I was just getting started and hadn't written any tests yet I deleted the entire target for the UI tests and re-added it. Same name and everything started working just fine.

If you run into this issue, its possible it is due to the naming. You can track it down that way or save your tests and re-add a UI target.

Tribrach answered 4/1, 2016 at 19:59 Comment(0)
B
4

I am getting the assertion

*** Assertion failure in -[XCUIApplication init], /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-8170.3/XCTestFramework/UI Testing/XCUIApplication.m:76

regularly, just as also described in other answers. Really annoying, and it took me some time to find the minimum steps to get rid of it.

The key solution I have found is to reboot your device. So, you don't need to remove the app, restart Xcode or something, just rebooting should make this assertion disappear.

Bova answered 13/9, 2016 at 11:18 Comment(2)
This saved my day. The tests daemon on the device seems not very stable.Yesima
@Yesima indeed the daemon is unresponsive. I even tried popping the cache on the phone without a restart and that didn't resolve it. Restarting worked for me, silly but effective fix. Thanks.Olindaolinde
G
2

After endless tweaking, changed the Location of Derived Data in "Xcode Preferences" from "Legacy" to "Custom" and got it to work!

enter image description here

Glynas answered 18/9, 2015 at 18:44 Comment(2)
Doing this does not fix the issue for me :(Outrelief
I'd downvote here, however as I lose score for doing it I won't do it. This is not the answer.Solidarity
G
2

I was getting this error after writing a few tests and running them. I tried all the fixes and suggestions posted but none of them worked for me.

I decided to delete the XCUI app that gets created whenever you run tests and restart my device and it worked. however if i run the tests 7 or 8 times afterwards, the error comes back and i just repeat the solution cycle. If you just delete the app and don't restart it won't work.

Not sure if this answer will work for everyone but this is what worked for me.

Gnomic answered 24/8, 2016 at 23:38 Comment(0)
S
2

Deleting the existing Target and creating again fixes the problem.

Make sure that you are selecting the right test bundle. For UI testing it should be "iOS UI Testing Bundle".

Synopsize answered 9/5, 2017 at 8:40 Comment(2)
That's the wrong answer. It should be "iOS UI Testing Bundle"Buddybuderus
modified. Bulls eye. :)Synopsize
O
1

It worked for me after I Comment the below code in setup() method of my TestCaseClass

continueAfterFailure = false & XCUIApplication().launch()

Ostiole answered 10/4, 2017 at 13:50 Comment(0)
E
1

Problem: Target application has been changed due to name change or any other change

Solution: GoTo > General > select the target application from here

enter image description here

Egesta answered 12/5, 2020 at 2:47 Comment(0)
F
0

I had this issue running Cucumberish tests on xCode 8.

I fixed by going Project ( In project navigator ) > MyTestTarget > General

Here make sure that the Target Application is set to the application you wish to run the tests against. By Default it was set to None.

Fisher answered 13/9, 2016 at 13:41 Comment(0)
B
0

This can be caused by your target not having the TEST_TARGET_NAME build setting, or it not matching the exact name of the target you are testing. Even if the "Target Application" set to your app in the "General" tab of the target, you still need TEST_TARGET_NAME setting in "Build Settings"

Beshrew answered 29/12, 2020 at 11:4 Comment(0)
P
0

I was getting this problem in Xcode 13.1. When I created the project there were two testing files. One file had @testable import TestingAButtonSwiftui at the top and the other didn't have this.

The not that doesn't have @testable import TestingAButtonSwiftui also had this function:

 func testExample() throws {
    // UI tests must launch the application that they test.
    let app = XCUIApplication()
    app.launch()

    // Use recording to get started writing UI tests.
    // Use XCTAssert and related functions to verify your tests produce the correct results.
}

when I placed what I wanted to test in here it worked.

enter image description here

Peri answered 7/11, 2021 at 22:33 Comment(0)
M
-1
  1. New create file UI Test Case and Unit Test Case templates are not much different , ( The former two lines of code ),Select Unit Test in the test will prompt "Application is not running",Adding "XCUIApplication().launch()" can solve the problem。
  2. When the test prompted not to find a control (E.g UITextField),Please set the control name \ identity -> accessibility -> Label \ to the same name as the control used in the UITestClass。
  3. You did not add the test class to the corresponding UI Targets。
Moffitt answered 15/9, 2017 at 2:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.