0

我正在尝试设置我的项目 TDD,所以我有以下单元测试:

- (void)testOnDoesUsernameExistsShouldReturnFalseWhenInvalidJSONResponseFromService {
    id mock = [OCMockObject partialMockForObject:(NSObject *) (id <ServiceHelperProtocol>) self.serviceHelper];
    [[[mock stub] andReturn:@"invalid-json-response"] get:[OCMArg any]];

    assertThat([self.signUpService doesUsernameExist:@"testusername"], true);
}

此测试针对此方法运行:

- (BOOL)doesUsernameExist:(NSString *)userName {
    NSString *url = [[NSString alloc] initWithFormat:@"%@/%@/api/signup.username_exists/?username=%@", kAPPLICATION_HOST, kAPPLICATION_NAME, userName];

    NSString *responseString = [self.serviceHelper get:url];
    if (responseString != nil && ![responseString isEqualToString:@""]) {
        @try {
            NSDictionary *dictionary = [responseString JSONValue]; // auto-released
            NSString *usernameExists = [dictionary objectForKey:@"username_exists"];
            return usernameExists != nil && ![usernameExists isEqualToString:@"null"];
        }
        @catch (NSException *e) {
            NSLog(@"Unable to parse JSON: %@", e.description);
        }
    }
    [responseString release];
    [url release];

    return false;
}

当我运行这个测试时,我在第 94 行(assertThat 行)收到以下警告:

passing argument 2 of 'HC_assertThatWithLocation' makes pointer from integer without a cast

当我替换宏时,我得到这行代码:

HC_assertThatWithLocation(self, [self.signUpService doesUsernameExist:@"testusername"], HC_is(0), "_file_name_", 0);

由于某种原因,我的测试失败了,但我不知道出了什么问题。测试用例是错误的,实现的方法是错误的还是与 OCMock 框架和 OCHamcrest 匹配器有关?

我将 Xcode 4.2 与 OCMock 1.66 和 OCHamcrest 1.7 一起使用。

有什么想法吗 ?

4

0 回答 0