2009-12-29 48 views
3

UITextFields是不是要成爲LogicTests的一部分,而不是ApplicationTest目標的一部分?iPhone UnitTesting UITextField值和等值線錯誤133

我有一個工廠類負責創建和返回(iPhone)UITextField,我試圖單元測試它。這是我的邏輯測試目標的一部分,當我嘗試建立並運行測試,我得到生成錯誤有關:

/Developer/Tools/RunPlatformUnitTests.include:451:0 試驗檯 「/開發人員/平臺/ iPhoneSimulator.platform /開發人員/ SDKs/iPhoneSimulator3.1.2.sdk/ '開發人員/ usr/bin/otest' 異常退出代碼133(它 可能已崩潰)。

在構建窗口,這點到下面一行: 「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 
+0

UITextFields也造成LogicTests失敗對我來說,這樣看來,你的觀察是正確的 - UITextFields並不意味着是LogicTests的一部分。 – 2010-04-08 14:13:42

回答

0

顯然,你不應該爲您的邏輯測試包含UITextField,但將它們移到您的應用程序測試中。

+1

如果這對你有用,你會將它標記爲接受的答案嗎? – Pops 2011-03-14 17:08:38

0

所以我也有同樣的問題.....任何解決方案?

我該如何解決它是創建一個DummyUITextField類,並將其注入到需要UITextField的類中。 (它就像一個模擬,但模擬將是錯誤的術語)。

@interface DummyUITextField : UIView { 

NSString *text; 

} 

@property (nonatomic, retain) NSString *text; 

@end 

然後,您可以添加您需要的任何其他方法到這個類。然而,如果你正在測試的代碼創建它自己的UITextField(而不是使用Interface Builder),那麼你將不得不尋找另一個解決方案。

感謝 戴夫

1

這是

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:]() 
...