我正试图运行GHUnit测试,以测试setter是否真的适用于我的应用程序中的NSManagedObject对象。我的应用程序名为Machine,我的GHUnit目标名为Tests。我已经将Machine添加为测试目标的依赖项。我在测试中的对象叫做Goal。这是代码,链接中的错误如下所示。
#import <GHUnitIOS/GHUnit.h>
#import <CoreData/CoreData.h>
#import "Goal.h"
#import "GoalRec.h"
@interface ControllerTests : GHTestCase { }
@property (retain) Goal *goal;
@end
@implementation ControllerTests
@synthesize goal;
- (BOOL)shouldRunOnMainThread {
// By default NO, but if you have a UI test or test dependent on running on the main thread return YES
return NO;
}
- (void)setUpClass {
// Run at start of all tests in the class
}
- (void)tearDownClass {
// Run at end of all tests in the class
}
- (void)setUp {
// Run before each test method
self.goal = [[[Goal alloc] init] autorelease];
}
- (void)tearDown {
// Run after each test method
self.goal = nil; // prevents memory leak
}
- (void)testImageArray {
NSString *str = @"Hello";
Goal *obj = self.goal;
obj.goal = str;
GHAssertEqualStrings(obj.goal, @"Hello", nil);
}
@结束
Ld/Users/dlwhitehurst/Library/Developer/Xcode/DerivedData/Machine cscchzscengbcmcmeyzxlkbhumdn/Build/Products/Debug iphonesimulator/Tests.app/Tests normal i386cd/用户/dlwhitehurst/开发/编码/Objective-C/iPad/machinesetenv MACOSX_DEPLOYMENT_TARGET 10.6setenv PATH"/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin:/Developer/usr/bin:/bin:/usr/sbin:/sbin"/开发者/平台/iPhone模拟器.平台/开发者/usr/bin/llvm-gcc-4.2-arch i386-isysroot/开发者/平台/IiPhoneSimulator.platform/开发者/sdk/iPhone模拟器4.3.sdk-L/Users/dlwhitehurst/Library/Developer/Xcode/DerivedData/Machine cscchzscengbcmcmeyzxlkbhumdn/Build/Products/Debug iPhoneSimulator-F/Users/dlwhitehurst/Library/Developer/Xcode/DerivedData/Machine cscchzscengbcmmeyzxlkbhumdn/Build/Products/Debug iphonesimulator-F/Users/dlwhite hurst/DDevelopment/Frameworks-filelist/Users/dlwhitehurst/Librare/Developer/Xcode/DerivedData/Machine CSCchzscenGBcmmeyz xlkbhumdn/Build/Inmediates/Machine.Build/Debug-iphonsimulator/Tests.Build/Objects-normal/i386/Tests.LinkFileList-mmacosx版本min=10.6-ObjC-all_load-Xlinker-ObjC_abi_version-Xlinker2-framework CoreData-framework GHUnitIOS-framework UIKit-framework Foundation-framework Core Graphics-o/Users/dlwhitehurst/Library/Developer/Xcode/DerivedData/Machine cscchzscengbcmcmmeyzxlkbhumdn/Build/Products/Debug iphonesimulator/Tests.app/Tests
体系结构i386的未定义符号:"_OBJC_CLASS_$_Goal",引用自:ControllerTests.o中的objc类引用ld:找不到体系结构i386的符号collect2:ld返回1退出状态
临时解决方案:
选择目标"测试"。选择"编译源"。然后添加"Goal.m",您将运行测试。
我也很困惑。我觉得这太疯狂了。相同:XCode 4单元测试的链接错误?
更好的解决方案可能是在为GHUnit测试创建目标时复制目标,而不是创建新目标。