I have the following class which I would like to mock in my tests. The class is only included in the "main"-target (i.e. not included in Test-target)
import Foundation
public class MyClass:NSObject {
public func doSomething() -> Bool{
return true
}
private func doesSomethingElse(){
println("Does something else")
}
}
The test class looks like this:
import UIKit
import XCTest
import TestTesting
class MyClassTest: XCTestCase {
override func setUp() {
super.setUp()
}
override func tearDown() {
super.tearDown()
}
}
class MockMyClass : MyClass {
override func doSomething() -> Bool{
println("I'm a mock")
return false
}
}
When running the release-configuration for the simulator, this works perfectly fine. But, when running this towards a device, I've been getting the following Build failure message:
Ld /Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Intermediates/TestTesting.build/Release-iphoneos/TestTestingTests.build/Objects-normal/arm64/TestTestingTests normal arm64
cd /Users/eaa/Development/ios-demo/TestTesting
export IPHONEOS_DEPLOYMENT_TARGET=8.0
export PATH="/Applications/http://ift.tt/1eHCv98"
/Applications/http://ift.tt/1jmLxI7 -arch arm64 -bundle -isysroot /Applications/http://ift.tt/1HPQoi0 -L/Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Products/Release-iphoneos -L/Users/eaa/Development/ios-demo/TestTesting/Pods/Google/Libraries -L/Users/eaa/Development/ios-demo/TestTesting/Pods/GoogleAnalytics/Libraries -L/Users/eaa/Development/ios-demo/TestTesting/Pods/GoogleNetworkingUtilities/Libraries -L/Users/eaa/Development/ios-demo/TestTesting/Pods/GoogleSymbolUtilities/Libraries -L/Users/eaa/Development/ios-demo/TestTesting/Pods/GoogleUtilities/Libraries -F/Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Products/Release-iphoneos -F/Applications/http://ift.tt/1HPQoi2 -F/Applications/http://ift.tt/XSNnte -F/Applications/http://ift.tt/1HPQoi2 -filelist /Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Intermediates/TestTesting.build/Release-iphoneos/TestTestingTests.build/Objects-normal/arm64/TestTestingTests.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @loader_path/Frameworks -dead_strip -bundle_loader /Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Products/Release-iphoneos/http://ift.tt/1HhoOce -framework XCTest -ObjC -lGGLAnalytics -lGGLCore -lGSDK_Overload -lGTMSessionFetcher_core -lGTMSessionFetcher_full -lGTMStackTrace -lGTM_AddressBook -lGTM_DebugUtils -lGTM_GTMURLBuilder -lGTM_KVO -lGTM_NSDictionary+URLArguments -lGTM_NSScannerJSON -lGTM_NSStringHTML -lGTM_NSStringXML -lGTM_Regex -lGTM_RoundedRectPath -lGTM_StringEncoding -lGTM_SystemVersion -lGTM_UIFont+LineHeight -lGTM_core -lGTM_iPhone -lGoogleAnalytics -lsqlite3 -lz -framework AddressBook -framework CoreData -framework SystemConfiguration -L/Applications/http://ift.tt/1wVc4DG -Xlinker -add_ast_path -Xlinker /Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Intermediates/TestTesting.build/Release-iphoneos/TestTestingTests.build/Objects-normal/arm64/TestTestingTests.swiftmodule -miphoneos-version-min=8.0 -lPods-TestTestingTests -Xlinker -dependency_info -Xlinker /Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Intermediates/TestTesting.build/Release-iphoneos/TestTestingTests.build/Objects-normal/arm64/TestTestingTests_dependency_info.dat -o /Users/eaa/Library/Developer/Xcode/DerivedData/TestTesting-bnkvoixgwmunpsdqtxkigrqlnxat/Build/Intermediates/TestTesting.build/Release-iphoneos/TestTestingTests.build/Objects-normal/arm64/TestTestingTests
Undefined symbols for architecture arm64:
"__TFC11TestTesting7MyClassP33_0C54D6EAECAD340035CBF1EA70A13B0A17doesSomethingElsefS0_FT_T_", referenced from:
_OBJC_CLASS_$__TtC16TestTestingTests11MockMyClass in MyClassTest.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
(Sorry, my current reputation won't allow me to post images)
The problem of course is that the Test-target cannot see the private method of MyClass. So I have a couple of questions:
1) Why can the simulator run this perfectly fine, while the device cannot?
2) What options do I have here? I could of course make everything public, but that can hardly be called a solution to the problem. I guess another solution could also be to create the mock in the production-target, but that's not an option the way I see it.
I'm using XCode 6.4 and Swift 1.2. The Build Active Architecture Only is set to NO on all Build Settings, and the Architectures build setting is set to Standard Architectures (armv7, arm64) - $(ARCHS_STANDARD). If there's any more information you need, I'll update the post. And the reason why I have not included the production-class to the test-config is mainly because of this article: http://ift.tt/1Gnjbvy
Also, I'm using CocoaPods if that is any crucial information.
Aucun commentaire:
Enregistrer un commentaire