Objective c Restkit单元测试映射到阵列
我正在尝试使用RKTestFixture测试RestKit对象到元素数组的映射 当我尝试只测试教程对象的一个元素(有名称和描述)时,使用下面的测试方法,一切都可以正常工作Objective c Restkit单元测试映射到阵列,objective-c,arrays,mapping,restkit-0.20,xctest,Objective C,Arrays,Mapping,Restkit 0.20,Xctest,我正在尝试使用RKTestFixture测试RestKit对象到元素数组的映射 当我尝试只测试教程对象的一个元素(有名称和描述)时,使用下面的测试方法,一切都可以正常工作 - (RKObjectMapping *)tutorialMapping { RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[Tutorial class]]; [objectMapping addAttributeMappi
- (RKObjectMapping *)tutorialMapping {
RKObjectMapping *objectMapping = [RKObjectMapping mappingForClass:[Tutorial class]];
[objectMapping addAttributeMappingsFromDictionary:@{
@"name" : @"name",
@"description" : @"description"
}];
return objectMapping;
}
- (void)testMappingOfDescriptionWithValue {
RKMappingTest *mappingTest = [RKMappingTest testForMapping:[self tutorialMapping] sourceObject:self.parsedJSON destinationObject:nil];
[mappingTest addExpectation:[RKPropertyMappingTestExpectation expectationWithSourceKeyPath:@"description"
destinationKeyPath:@"description"
value:@"This is an example description"]];
XCTAssert([mappingTest evaluate]);
}
但是,当我尝试使用evaluationBlocks测试一系列教程对象(如下面的一个)时,我无法获得正确的映射
[
{
"name": "Tutorial name 1",
"description": "This is an example description"
},
{
"name": "Tutorial name 2",
"description": "This is an example description"
}
]
有人能解决这个问题吗?谷歌没有让我通过它
更新
我使用Fixtures功能发送JSON:
NSBundle *testTargetBundle = [NSBundle bundleForClass:[self class]];
[RKTestFixture setFixtureBundle:testTargetBundle];
self.parsedJSON = [RKTestFixture parsedObjectWithContentsOfFixture:@"tutorials.json"];
在我的测试方法中:
RKMappingTest *mappingTest = [RKMappingTest testForMapping:[self tutorialMapping] sourceObject:self.parsedJSON destinationObject:nil];
尝试打开跟踪日志记录并使用
evaluateExpectation:error:
,以便查看返回的error
内容。日志消息返回:expections:()事件:(“RKMappingTestEvent映射的sourceKeyPath'imageUrl=>destinationKeyPath'imageUrl',值为:(null)>”,“RkmapingTestEvent映射的sourceKeyPath'description'=>destinationKeyPath'description'带有值:(null)>”:映射“(null)”到“(null)”,但没有映射。}
对于mappingTest:[mappingTest EvaluateExpection:[RKPropertyMappingTest evaluateExpectation:[RKPropertyMappingTestExpectationExpectationWithSourceKeyPath:nil destinationKeyPath:nil evaluationBlock:^BOOL(…){return true;}]error:&error];
您是如何向测试提供JSON的?您在运行测试时检查(记录)了它吗?我更新了我的问题。感谢您的帮助!我还没有真正帮助:-)我只是试图获得证据证明测试的所有输入都是正确的(因此请求记录输入和错误)。