在 Xcode 中,我正在运行基于 ID 创建用户的测试。当设置了错误的 ID 时,测试应该会失败。虽然这个测试失败了,因为它测试的方法本身就有断言:
[[Apiclient sharedClient] findAndCreateUserWithID:nil success:^(Player *player) {
STFail(@"should not be able to create player with no ID");
} failure:^(NSError *error) {
}];
该方法称为:
- (void)findAndCreateUserWithID:(NSNumber *)ID success:(void (^)(Player *))createdPlayer failure:(void (^)(NSError *error))failure
{
NSParameterAssert(ID);
当参数 ID 为 nil 时测试失败。我知道这是一个非常愚蠢的例子,因为它总是会失败,但是代码中已经有了更多更有用的断言。运行 Xcode 单元测试的最佳实践是什么,哪些测试代码已经有了断言?