iPhone UnitTesting UITextField 值和测试错误 133

标签 iphone objective-c

UITextFields 不是 LogicTest 的一部分而是 ApplicationTest 目标的一部分吗?

我有一个负责创建和返回 (iPhone) UITextField 的工厂类,我正在尝试对其进行单元测试。它是我的逻辑测试目标的一部分,当我尝试构建和运行测试时,我收到一个构建错误:

/Developer/Tools/RunPlatformUnitTests.include:451:0 Test rig '/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator3.1.2.sdk/ 'Developer/usr/bin/otest' exited abnormally with code 133 (it may have crashed).

在构建窗口中,这指向以下行:“RunPlatformUnitTests.include”

RPUTIFail ${LINENO} "Test rig '${TEST_RIG}' exited abnormally with code ${TEST_RIG_RESULT} (it may have crashed)."

我的单元测试是这样的:

#import <SenTestingKit/SenTestingKit.h>
#import <UIKit/UIKit.h>

// Test-subject headers.
#import "TextFieldFactory.h"

@interface TextFieldFactoryTests : SenTestCase {    

}
@end

@implementation TextFieldFactoryTests

#pragma mark Test Setup/teardown
- (void) setUp {
    NSLog(@"%@ setUp", self.name);      
}

- (void) tearDown {
    NSLog(@"%@ tearDown", self.name);
}

#pragma mark Tests
- (void) testUITextField_NotASecureField
{
    NSLog(@"%@ start", self.name);   
    UITextField *textField = [TextFieldFactory createTextField:YES];    
    NSLog(@"%@ end", self.name); 
}

我要测试的类:

// Header file
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@interface TextFieldFactory : NSObject {

}

+(UITextField *)createTextField:(BOOL)isSecureField;

@end

// Implementation file
#import "TextFieldFactory.h"

@implementation TextFieldFactory

+(UITextField *)createTextField:(BOOL)isSecureField                   
{
    // x,y,z,w are constants declared else where   
    UITextField *textField = [[[UITextField alloc] 
            initWithFrame:CGRectMake(x, y, z, w)] 
            autorelease];

    // some initialization code

    return textField;   
}

@end

最佳答案

这是

的副本

Why does instantiating a UIFont in an iphone unit test cause a crash?

这是回溯:

#0  0x004899d1 in __HALT ()
#1  0x003d576d in _CFRuntimeCreateInstance ()
#2  0x00c57ef0 in GSFontCreateWithName ()
#3  0x03fccc72 in +[UIFont systemFontOfSize:] ()
#4  0x03f80766 in +[UILabel defaultFont] ()
#5  0x03f82ec4 in -[UILabel _commonInit] ()
#6  0x03f80d3a in -[UILabel initWithFrame:] ()
#7  0x03efbde8 in -[UITextField createTextLabelWithTextColor:] ()
#8  0x03f03e1a in -[UITextField initWithFrame:] ()
#9  0x00c52d75 in +[TextFieldFactory createTextField:] (self=0xc5308c, _cmd=0x8400b50, isSecureField=1 '\001') at /Users/dmaclach/Desktop/test/Classes/untitled2.m:19
#10 0x00c52c98 in -[TextFieldFactoryTests testUITextField_NotASecureField] (self=0x2161bf0, _cmd=0xc52dfe) at /Users/dmaclach/Desktop/test/Classes/untitled.m:26
#11 0x0043642d in __invoking___ ()
#12 0x00436301 in -[NSInvocation invoke] ()
#13 0x20104632 in -[SenTestCase invokeTest] ()
#14 0x20104d07 in -[SenTestCase performTest:] ()
...

关于iPhone UnitTesting UITextField 值和测试错误 133,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1976539/

相关文章:

objective-c - 如何在 Objective-C 中正确地子类化委托(delegate)属性?

ios - 如何 "simplify"UIImagePickerController

ios - IOS7中的UIButton背景图片

iphone - UIDatePicker 仅显示月份和日期

iphone - 删除使用 KeychainItemWrapper iphone-sdk 存储的用户名/密码

iphone - 强制核心位置使用 gps

objective-c - 制作自定义 NSMenuItem View 时如何反转 NSImageNameMenuOnStateTemplate 图像?

iphone - iphone 中的日期选择器

iphone - 以编程方式更改 UIButton 标题

ios - 自定义导航栏图像 - iOS 7