首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于iOS的Mantle模型误差测试

基于iOS的Mantle模型误差测试
EN

Stack Overflow用户
提问于 2014-06-04 21:43:12
回答 1查看 1.7K关注 0票数 0

给定以下简单的模型类(基于Mantle):

代码语言:javascript
复制
// .h
#import <Mantle.h>

@interface JAIInterestingPhonesCategory : MTLModel <MTLJSONSerializing>

@property (copy, nonatomic, readonly) NSString *categoryId;
@property (copy, nonatomic, readonly) NSString *title;

@end

// .m
#import "JAIInterestingPhonesCategory.h"

@implementation JAIInterestingPhonesCategory

+ (NSDictionary *)JSONKeyPathsByPropertyKey
{
    return @{
             @"categoryId"  : @"id",
             };
}

@end

我创建了以下TestCase:

代码语言:javascript
复制
#import <XCTest/XCTest.h>
#import "JAIInterestingPhonesCategory.h"

@interface JAIInterestinPhoneTestCase : XCTestCase

@end

@implementation JAIInterestinPhoneTestCase

- (void)setUp
{
    [super setUp];
    // Put setup code here. This method is called before the invocation of each test method in the class.
}

- (void)tearDown
{
    // Put teardown code here. This method is called after the invocation of each test method in the class.
    [super tearDown];
}

- (void)testCreateModelWithJSONDictionary
{
    NSDictionary *JSONModelDictionary = @{
                                          @"id"     : @"catId",
                                          @"title"  : @"Category title"
                                          };

    NSError *error;
    JAIInterestingPhonesCategory *category = [MTLJSONAdapter modelOfClass:[JAIInterestingPhonesCategory class] fromJSONDictionary:JSONModelDictionary error:&error];
    XCTAssertNotNil(category, @"The instantiated category must not be nil");

}

@end

我得到了折叠运行时错误:

*** Assertion failure in -[MTLJSONAdapter initWithJSONDictionary:modelClass:error:] Invalid parameter not satisfying: [modelClass isSubclassOfClass:MTLModel.class]

正如你所看到的,modelClass(a.k.a. )JAIInterestingPhonesCategory)是MTLModel的一个子类。

我把Mantle作为一个Pod加入了这个项目。

知道这是怎么回事吗?谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-06-05 10:37:12

这里的问题是,Mantle被注入您的测试和您的主要目标。

这里的解决方案是相应地更改podfile:

代码语言:javascript
复制
platform :ios, '7.0'

target :app do
    pod 'Mantle', '~> 1.4'
end

target :appTests do
  pod 'Expecta',     '~> 0.3'
end

有关更多信息,请访问https://github.com/Mantle/Mantle/issues/217。祝好运!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24048112

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档