单元测试时找不到枚举描述符PBFieldDescriptorProto_Label [英] Unable to find enum descriptor PBFieldDescriptorProto_Label while unit testing

查看:119
本文介绍了单元测试时找不到枚举描述符PBFieldDescriptorProto_Label的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将GoogleCast框架添加到单元测试目标后,在测试开始运行之前,我得到了以下异常.除此之外,SDK可以正常运行.我将不胜感激!

After adding the GoogleCast framework to the unit test target I'm getting the following exception right before the tests start to run. Apart from that the SDK is fully functional. I'd appreciate any ideas!

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的行为是遍历每个类并因此调用+initialize:

OCUnit's behaviour is to go through each class and hence call +initialize:

但是GCKPB_PBGeneratedMessage无法正确处理此问题,并且已经报告了该错误

But this is not handled properly by GCKPB_PBGeneratedMessage and this bug has already been reported here.

在等待修复时,一个临时的解决方案可能是在OCMock(或任何其他模拟框架)的单元测试中模拟GCKPB_PBGeneratedMessage+initialize方法,方法是在测试类中添加以下代码:

While waiting for a fix, a temporary solution might be to mock GCKPB_PBGeneratedMessage's +initialize method in your unit tests with OCMock (or any other mocking framework) by adding the following code to your test class:

#import <OCMock/OCMock.h>

@interface GCKPB_PBGeneratedMessage : NSObject
@end

+ (void)initialize
{
    id mockCastGeneratedMessage = [OCMockObject mockForClass:[GCKPB_PBGeneratedMessage class]];
    [[mockCastGeneratedMessage stub] initialize];
}

修改

自iOS发送器API v2.3.0 953起,此问题已修复,不再需要此解决方法.

As of iOS sender API v2.3.0 953, this is now fixed and this workaround is no longer required.

这篇关于单元测试时找不到枚举描述符PBFieldDescriptorProto_Label的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆