XCTest - “Test failed”

2020-03-02 02:15发布

问题:

I'm trying to add tests to a mac app. I'm using XCTest framework. When i run tests (cmd + U) i receive "Test failed" and in console I see :

2013-10-15 13:22:56.354 8tracks Radio[40560:303] Error loading /Users/victor/Library/Developer/Xcode/DerivedData/Musica-dhxbqwburbddtietormguodcwoqt/Build/Products/Test/MusicaTests.octest/Contents/MacOS/MusicaTests:  dlopen(/Users/victor/Library/Developer/Xcode/DerivedData/Musica-dhxbqwburbddtietormguodcwoqt/Build/Products/Test/MusicaTests.octest/Contents/MacOS/MusicaTests, 262): no suitable image found.  Did find:
/Users/victor/Library/Developer/Xcode/DerivedData/Musica-dhxbqwburbddtietormguodcwoqt/Build/Products/Test/MusicaTests.octest/Contents/MacOS/MusicaTests: open() failed with errno=1IDEBundleInjection.c: Error loading bundle '/Users/victor/Library/Developer/Xcode/DerivedData/Musica-dhxbqwburbddtietormguodcwoqt/Build/Products/Test/MusicaTests.octest'

Any ideas? Cheers!

回答1:

You need to disable code signing in order to run unit tests. This page explains how to create a configuration for testing so that your debug and release applications are code signed but your unit tests are not. Don't forget to do a full clean after changing the configuration.



回答2:

I had the same "no suitable image found" issue when was trying to add tests to an existing ios project. Try to go to Build Settings of your Tests target and set "Build Active Architecture Only" to "No". This solved my issue.

Also, make sure you have the same Architecture for both targets or you'll get strange linker errors.



回答3:

I was facing a different issue but was seeing the same log. For the problem was that the deployment target of the tests target was higher than the iOS version of the simulator that I was trying to use.

I hope this helps someone.