I am building a dynamic Cocoa Framework (let's say MyFrame) using Swift 1.2 and Xcode 6.4. I am using SwiftyJSON as a linked framework in MyFrame after downloading it using Carthage. It builds and runs perfectly. I wrote unit tests in a XCTestCase. The testing target is MyFrameTests. It works perfectly as long as MyFrame does not use SwiftyJSON. When I add SwiftyJSON in MyFrame, I get the following error:
2015-08-25 18:22:25.653 xctest[17732:237778] The test bundle at /Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest could not be loaded because an unanticipated error occurred.
2015-08-25 18:22:25.654 xctest[17732:237778] Detailed error information: Error Domain=NSCocoaErrorDomain Code=3587 "The bundle “MyFrameTests” couldn’t be loaded because it is damaged or missing necessary resources." (dlopen_preflight(/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests): Library not loaded: @rpath/SwiftyJSON.framework/SwiftyJSON
Referenced from: /Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests
Reason: image not found) UserInfo=0x7f8e13705070 {NSLocalizedFailureReason=The bundle is damaged or missing necessary resources., NSLocalizedRecoverySuggestion=Try reinstalling the bundle., NSFilePath=/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests, NSDebugDescription=dlopen_preflight(/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests): Library not loaded: @rpath/SwiftyJSON.framework/SwiftyJSON
Referenced from: /Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest/MyFrameTests
Reason: image not found, NSBundlePath=/Users/manonh/try16/MyFrame/DerivedData/MyFrame/Build/Products/Debug-iphonesimulator/MyFrameTests.xctest, NSLocalizedDescription=The bundle “MyFrameTests” couldn’t be loaded because it is damaged or missing necessary resources.}
*** Test session exited(1) without checking in. If you believe this error represents a bug, please attach the log file at /var/folders/9g/jxyyssdx0xn9xp_29fg2l9080000gq/T/com.apple.dt.XCTest-status/Session-2015-08-25_18:22:25-2wDwFh.log
I googled this and found some things about defines module and other options in Build Settings > Packaging. Did not work.
I have tried to add import SwiftyJSON
inside the test swift file. Did not work
I also tried to put SwiftyJSON in Copy Bundle Resource in MyFrame. Did not work
In MyFrameTests, I tried to add SwiftyJSON in Link Binary With Libraries and Copy Bundle Resource. I tried all the combinations of the above "locations" of SwiftyJSON framework. Did not work
After 2 days of struggling and googling and reading other stackoverflow posts, I haven't found a way to run this test.
Is there anyone that knows how to unit test a cocoa framework that has a dependency?
Thanks in advance for the help!
Below is the very basic class I want to test in MyFrame and the testcase in MyFrameTests, if it can be of any use.
MyFrameClass.swift
import Foundation
import SwiftyJSON
public class MyFrameClass {
public init() {}
public func getFive() -> Int {
return 5
}
}
MyFrameTests.swift
import UIKit
import XCTest
import MyFrame
class test18Tests: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
func testExample() {
XCTAssert(true, "Pass")
}
func testExample2() {
var c = MyFrameClass()
XCTAssertEqual(c.getFive(), 5, "Five test of MyFrameClass")
}
func testPerformanceExample() {
// This is an example of a performance test case.
self.measureBlock() {
// Put the code you want to measure the time of here.
}
}
}
Just remove import SwiftyJSON
from MyFrameClass.swift and it works like a charm.
Aucun commentaire:
Enregistrer un commentaire