我正在尝试熟悉Kiwi BDD 测试框架。我将它与Nocilla结合使用来模拟 HTTP 请求。这两个项目看起来都很棒,但我遇到了一些困难。我有以下测试规范:
beforeAll(^{ // Occurs once
[[LSNocilla sharedInstance] start];
});
afterAll(^{ // Occurs once
[[LSNocilla sharedInstance] stop];
});
beforeEach(^{ // Occurs before each enclosed "it"
couch = [[Couch alloc]initWithDatabaseUrl:@"http://myhost/mydatabase"];
});
afterEach(^{ // Occurs after each enclosed "it"
[[LSNocilla sharedInstance] clearStubs];
});
it(@"should be initialized", ^{
[couch shouldNotBeNil];
});
context(@"GET requests", ^{
it(@"should get document by id", ^{
__block NSData *successJson = nil;
__block NSError *requestErr = nil;
stubRequest(@"GET", @"http://myhost/mydatabase/test").
withHeader(@"Accept", @"application/json").
withBody(@"{\"_id\":\"test\",\"_rev\":\"2-77f66380e1670f1876f15ebd66f4e322\",\"name\":\"nick\"");
[couch getDocumentById:@"test" success:^(NSData *json){
successJson = json;
} failure:^(NSError *error) {
requestErr = error;
}];
[[successJson shouldNot]equal:nil];
});
});
抱歉,代码片段很长。我想确保我给出上下文。如您所见,我正在测试发出 GET 请求并在“成功”块中报告结果并在“失败”块中报告错误的对象的行为。我有两个 __block 变量来接受存储成功和失败。目前,测试检查“成功”变量是否有值(不是零)。该测试通过。但是,调试此测试似乎从未执行过任何块。successJson 显示为零。我希望 Nocilla 已将存根正文内容传递给成功块参数。那么我的测试构造不正确吗?
谢谢!