Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/122.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 单元测试时找不到枚举描述符PBFieldDescriptorProto_标签_Ios_Google Cast - Fatal编程技术网

Ios 单元测试时找不到枚举描述符PBFieldDescriptorProto_标签

Ios 单元测试时找不到枚举描述符PBFieldDescriptorProto_标签,ios,google-cast,Ios,Google Cast,在将GoogleCast框架添加到单元测试目标之后,在测试开始运行之前,我得到了以下异常。除此之外,SDK功能齐全。如果有任何想法,我将不胜感激 2014-02-25 18:03:08.475 otest[3786:303] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size 2014-02-25 18:03:08.593 otest[3786:303] *** Assertion failure i

在将GoogleCast框架添加到单元测试目标之后,在测试开始运行之前,我得到了以下异常。除此之外,SDK功能齐全。如果有任何想法,我将不胜感激

2014-02-25 18:03:08.475 otest[3786:303] Unknown Device Type. Using UIUserInterfaceIdiomPhone based on screen size
2014-02-25 18:03:08.593 otest[3786:303] *** Assertion failure in -[GCKPB_PBFieldDescriptor initWithFieldDescription:rootClass:], /Volumes/BuildData/pulse-data/agents/wpye22.hot/recipes/415961027/base/googlemac/iPhone/Chromecast/SDKv2/Protos/../../../../ThirdParty/ProtocolBuffers/objectivec/Classes/PBDescriptor.m:409
2014-02-25 18:03:08.596 otest[3786:303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to find enum descriptor PBFieldDescriptorProto_Label'
*** First throw call stack:
(
    0   CoreFoundation                      0x00b1d5e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x007958b6 objc_exception_throw + 44
    2   CoreFoundation                      0x00b1d448 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x00010fee -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   UnitTests                           0x077205dd -[GCKPB_PBFieldDescriptor initWithFieldDescription:rootClass:] + 1640
    5   UnitTests                           0x0771f52c +[GCKPB_PBDescriptor allocDescriptorForClass:rootClass:fields:fieldCount:enums:enumCount:ranges:rangeCount:storageSize:wireFormat:] + 173
    6   UnitTests                           0x076e550f +[GCKPB_PBFieldDescriptorProto descriptor] + 179
    7   UnitTests                           0x077226b2 +[GCKPB_PBGeneratedMessage initialize] + 100
    8   libobjc.A.dylib                     0x00796275 _class_initialize + 599
    9   libobjc.A.dylib                     0x0079d0f1 lookUpImpOrForward + 158
    10  libobjc.A.dylib                     0x0079d04e _class_lookupMethodAndLoadCache3 + 55
    11  libobjc.A.dylib                     0x007a512f objc_msgSend + 139
    12  SenTestingKit                       0x201086c6 +[NSObject(SenTestRuntimeUtilities) senIsASuperclassOfClass:] + 74
    13  SenTestingKit                       0x2010879e +[NSObject(SenTestRuntimeUtilities) senAllSubclasses] + 154
    14  SenTestingKit                       0x20106fa0 +[SenTestSuite updateCache] + 42
    15  SenTestingKit                       0x201071cf +[SenTestSuite suiteForBundleCache] + 93
    16  SenTestingKit                       0x20107241 +[SenTestSuite testSuiteForBundlePath:] + 101
    17  SenTestingKit                       0x201061fb +[SenTestProbe specifiedTestSuite] + 294
    18  SenTestingKit                       0x20106467 +[SenTestProbe runTests:] + 177
    19  libobjc.A.dylib                     0x007a7737 +[NSObject performSelector:withObject:] + 70
    20  otest                               0x00002372 otest + 4978
    21  otest                               0x000025c4 otest + 5572
    22  otest                               0x000026a5 otest + 5797
    23  otest                               0x00002031 otest + 4145
    24  libdyld.dylib                       0x0165570d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

OCUnit的行为是遍历每个类,然后调用
+初始化:

但是,
GCKPB_PBGeneratedMessage
没有正确处理这一问题,并且已经报告了此错误

在等待修复时,临时解决方案可能是通过将以下代码添加到测试类中,在使用OCMock(或任何其他模拟框架)的单元测试中模拟
GCKPB\PBGeneratedMessage
+initialize方法:

#导入
@接口GCKPB_PBGeneratedMessage:NSObject
@结束

+(void)初始化
{
id mockCastGeneratedMessage=[OCMockObject mockForClass:[GCKPBPBUGeneratedMessage class]];
[[MockCastGeneratedMessageStub]初始化];
}
编辑


从iOS sender API v2.3.0 953开始,这一问题现已得到解决,不再需要此解决方法。

我在使用Specta进行单元测试时遇到类似错误。我通过创建自己的断言处理程序手动忽略了断言

在助手类中定义:

#define SPT_fail(...) \
    SPTSpec *spec = [[SPTCurrentTestCase class] spt_spec];                                                                         \
    NSString *message = [NSString stringWithFormat:__VA_ARGS__];                                                                \
    [SPTCurrentTestCase recordFailureWithDescription:message inFile:spec.fileName atLine:(int)spec.lineNumber expected:YES];                                                                             \
xxxLoggingAssertionHandler.m:

@implementation xxxLoggingAssertionHandler

+ (void)load {
    [xxxLoggingAssertionHandler addHandler];
}

- (void)handleFailureInMethod:(SEL)selector
                       object:(id)object
                         file:(NSString *)fileName
                   lineNumber:(NSInteger)line
                  description:(NSString *)format, ... {

    // ignore chromecast asserts only
    NSString *selectorName = NSStringFromSelector(selector);
    BOOL ignore = [selectorName isEqualToString:@"initWithFieldDescription:rootClass:"] || [selectorName isEqualToString:@"allocDescriptorForClass:rootClass:fields:fieldCount:enums:enumCount:ranges:rangeCount:storageSize:wireFormat:"];

    if (!ignore) {
        SPT_fail(@"NSAssert Failure: Method %@ for object %@ in %@#%i", selectorName, object, fileName, line);
    }
}

- (void)handleFailureInFunction:(NSString *)functionName
                           file:(NSString *)fileName
                     lineNumber:(NSInteger)line
                    description:(NSString *)format, ... {
    SPT_fail(@"NSCAssert Failure: Function (%@) in %@#%i", functionName, fileName, line);
}

+ (void)addHandler {
    NSAssertionHandler *assertionHandler = [[xxxLoggingAssertionHandler alloc] init];
    [[[NSThread currentThread] threadDictionary] setValue:assertionHandler
                                                   forKey:NSAssertionHandlerKey];
}

+ (void)removeHandler {
    [[[NSThread currentThread] threadDictionary] setValue:nil
                                                   forKey:NSAssertionHandlerKey];
}

@end

哇,太棒了!谢谢。一个新的问题也许能更好地解决这个问题,但我想先问一下:有没有可能有人已经为猕猴桃找到了答案?我试着用KWMock做类似的模拟,但不起作用。