ios - bloc.io : failing XTCAssertTest for unknown reasons; previously successful in mock app

标签 ios objective-c macos unit-testing

目前在 bloc.io 的 iOS 类(class)中。写了一个测试失败的方法,我不知道为什么。

[背景:现在已经研究了 4 个小时,搜索了 stackOverflow 和我的类(class) Material 以确保我理解循环、可变字符串、附加可变字符串以及将整数放入字符串中。]

使用我用来测试的基本应用程序实践项目,我编写了一个使用 NSLog 的方法来验证字符串中的内容,它非常有效。

当我将方法复制并粘贴到 bloc.io 练习时,它未能通过测试,在我看来它不应该失败。

1) 最初在我的“练习应用程序”中起作用的是什么

- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:
(NSDictionary *)launchOptions {

NSMutableString* numberString = [[NSMutableString alloc] init];
for(int index=-7;index<=13;index++)
{
    [numberString appendString:[NSString stringWithFormat:@"%d",index]];
}
NSLog(@"Content in MutableString: %@", numberString);
// return @"numberString";
return YES;
}

2) #1 的输出:

Content in MutableString: -7-6-5-4-3-2-1012345678910111213 // so far so good

3) 适用于本练习的“复制粘贴版”:

- (NSString *) stringWithNumbersBetweenNumber:(NSInteger)number andOtherNumber:(NSInteger)otherNumber
{
NSMutableString* numberString = [[NSMutableString alloc] init];
for(NSinteger index=number;index<=otherNumber;index++)
{
    [numberString appendString:[NSString stringWithFormat:@"%ld",(long)index]];
}
//    NSLog(@"Content in MutableString: %@", numberString);
return @"numberString";
}

4) 我不明白为什么失败的测试:

- (void)testThatStringWorksAscending {
NSInteger lowNumber = -7;
NSInteger highNumber = 13;
NSString *expectedString = @"-7-6-5-4-3-2-1012345678910111213";
NSString *actualString = [self.counter stringWithNumbersBetweenNumber:lowNumber andOtherNumber:highNumber];
XCTAssertEqualObjects(expectedString, actualString, @"strings differed");
}

最佳答案

哎呀。多亏了我很棒的集团导师史蒂夫,我才弄明白。我不应该用

    return @"numberString";

而是:

return numberString;

区别在于文字字符串与变量,我需要更好地理解这一点..

关于ios - bloc.io : failing XTCAssertTest for unknown reasons; previously successful in mock app,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28754985/

相关文章:

macos - 如何为 Mac OS X 制作可启动 DVD?

java - log4j: 找不到资源

ios - 设置自定义 UITextField

iPhone 本地通知不会出现

iOS 用户界面测试 : Failure getting list of active applications: AX error -25205

objective-c - 选择器 OpenDevice 的未知类方法

objective-c - 有没有办法在使用 stringFromContentsOfURL 加载资源时将其编码为 "auto detect"?

objective-c - applicationShouldOpenUntitledFile 返回 NO,但应用程序仍然打开空白文档

java - 我应该使用哪些技术来提供开箱即用的服务器安装

ios - 在 Swift 中检测 CAShapeLayer 上的点击?