我是 Objective-c 的新手,我发现我不知道如何正确断言某个给定标签上的文本属性等于原始字符串值。我不确定是否只需将标签转换为 NSString 或者是否需要直接修改我的断言语句。
@interface MoreTest : SenTestCase {
MagiczzTestingViewController* controller;
}
- (void) testObj;
@end
@implementation MoreTest
- (void) setUp
{
controller = [[MagiczzTestingViewController alloc] init];
}
- (void) tearDown
{
[controller release];
}
- (void) testObj
{
controller.doMagic;
STAssertEquals(@"hehe", controller.label.text, @"should be hehe, was %d instead", valtxt);
}
@end
我的 doMagic 方法的实现如下
@interface MagiczzTestingViewController : UIViewController {
IBOutlet UILabel *label;
}
@property (nonatomic, retain) UILabel *label;
- (void) doMagic;
@end
@implementation MagiczzTestingViewController
@synthesize label;
- (void) doMagic
{
label.text = @"hehe";
}
- (void)dealloc {
[label release];
[super dealloc];
}
@end
当我修改断言以将原始 NSString 与另一个进行比较时,构建很好,但是当我尝试捕获文本值(假设它是 NSString 类型)时,它失败了。任何帮助将非常感激!