使用 Xcode 7 运行 UITesting 时出现“NSInternalInconsistencyException”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32276523/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 07:44:10  来源:igfitidea点击:

‘NSInternalInconsistencyException’ when running UITesting with Xcode 7

iosxcodeswiftxcode7xcode-ui-testing

提问by SuPotter

Ok, I've not been able to run this test in any betas so far. Some of the issues I've encountered are hereand 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
  1. 在创建新项目时启用“UI 测试”选项。这,实际上为我增加了一个目标。所以我应该很高兴去 - 或者我想。 在此处输入图片说明
  2. UI测试下的swift文件已经导入了“XCTest”,是“XCTestCase”的子类。
  3. setup() 启动应用程序 XCUIApplication().launch()
  4. 我添加了以下内容(通过点击“录制”按钮) 在此处输入图片说明

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

甚至在调用测试之前,整个事情都失败了,就在 setup() 中启动应用程序后,使用以下内容

*** 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

*** 断言失败 -[XCUIApplication init], /Library/Caches/com.apple.xbs/Sources/XCTest_Sim/XCTest-8170.3/XCTestFramework/UI Testing/XCUIApplication.m:76 /Users/UserName/Documents/Projects/测试/UiTesting/UITestingApp/UITestingApp.swift:0:错误:-[UITestingApp.UITestingApp testSimpleTap]:失败:捕获“NSInternalInconsistencyException”,“未通过测试配置指定目标应用程序路径:
testBundleURL:file:///Users/UserName/库/开发者/CoreSimulator/设备/E3201DC2-CAD3-48C3-95F5-15E18DCA1836/data/Containers/Bundle/Application/8B33FC59-FC03-41F8-BD21-43D81BA2D355/UITesting/UITestingApp-AppIn.
productModuleName:(null)testToSkip:(null)testsToRun:(null)reportResultsToIDE:no sessionIdentifier:<__NSConcreteUUID 0x7f93e146c0b0> F242796B-ED26-4AA7-861A-540D2D93CB8F01000D2D93CB8F PathingReactReactReleaseFilesPathingFilesToIDE(FALSE) :(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

注意:我确实将 UI 测试目标的“目标应用程序”设置为我的应用程序

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

更新:我注意到这适用于 Xcode 的所有测试版/最终版本 - 相应地更新了标题

采纳答案by SuPotter

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

经过无休止的调整后,将“Xcode 首选项”中的“派生数据位置”从“传统”更改为“自定义”并使其正常工作!

enter image description here

在此处输入图片说明

回答by Matt Bearson

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"

我有一个类似的问题,我的错误是尝试在常规测试目标中使用 UI 测试代码。一旦我创建了一个新目标,从“iOS UI 测试包”开始并在那里复制代码,错误就消失了。这是为我指明正确方向的线程:https: //twitter.com/punksomething/status/609505357132500993“是的,我试图在常规测试目标中使用 UI 测试。不得不创建一个新添加的 UI 测试目标”

回答by Viktor Kucera

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.

当我尝试向我的单元测试目标添加一个新类但我选择了 UI 测试用例类模板而不是单元测试用例类模板时,这发生在我身上。

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.

确保您始终选择正确的一个。尽管它们都是 XCTestCase 子类并且您将它们分配给正确的目标,但在选择错误模板时会抛出此错误。

enter image description here

在此处输入图片说明

回答by TibiUr

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.

重命名目标后我得到了这个。解决方案是在我的 UITest 目标中将“目标应用程序”设置为“无”并点击构建。在此之后,我将“无”设置回我的应用程序并解决了错误。我认为重命名很可能弄乱了 ui 测试目标的“目标应用程序”设置。

回答by Samu?l

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

*** 断言失败 -[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.

我发现的关键解决方案是重新启动您的设备。因此,您不需要删除应用程序、重新启动 Xcode 或其他什么,只需重新启动即可使此断言消失。

回答by Bill Burgess

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.

我有这个确切的问题。我认为这个问题源于沿途重命名目标。这里的任何修复都没有帮助我解决我的问题。由于我刚刚开始并且还没有编写任何测试,因此我删除了 UI 测试的整个目标并重新添加了它。同名,一切开始正常。

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.

如果您遇到此问题,可能是由于命名造成的。您可以通过这种方式对其进行跟踪或保存您的测试并重新添加 UI 目标。

回答by Bori Oludemi

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.

我决定删除每次运行测试时创建的 XCUI 应用程序并重新启动我的设备并且它工作正常。但是,如果我之后运行测试 7 或 8 次,错误又会出现,我只是重复解决方案周期。如果您只是删除该应用程序而不重新启动它,它将无法工作。

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

不确定这个答案是否适用于所有人,但这对我有用。

回答by arango_86

Deleting the existing Target and creating again fixes the problem.

删除现有的 Target 并再次创建可以解决问题。

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

确保您选择了正确的测试包。对于 UI 测试,它应该是“ iOS UI 测试包”。

回答by Ranganatha G V

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

在我的 TestCaseClass 的 setup() 方法中注释以下代码后,它对我有用

continueAfterFailure = false & XCUIApplication().launch()

continueAfterFailure = false & XCUIApplication().launch()

回答by Alok

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

在此处输入图片说明