ios – Xcode 7魔法记录单元测试失败

前端之家收集整理的这篇文章主要介绍了ios – Xcode 7魔法记录单元测试失败前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Xcode 6.4升级Xcode 7(现在为7.0.1)后,我的项目在启动单元测试时会崩溃.我的iOS项目正在使用魔法记录,应用程序在这个断言中崩溃:
  1. + (NSManagedObjectContext *) MR_defaultContext
  2. {
  3. @synchronized(self) {
  4. NSAssert(MagicalRecordDefaultContext != nil,@"Default context is nil! Did you forget to initialize the Core Data Stack?");
  5. return MagicalRecordDefaultContext;
  6. }
  7. }

我已经评论过我以前的所有测试,并且这两个测试都显示出相同的行为:

  1. #import <XCTest/XCTest.h>
  2.  
  3. @interface BadTests : XCTestCase
  4.  
  5. @end
  6.  
  7. @implementation BadTests
  8.  
  9. - (void)setUp {
  10. [super setUp];
  11. }
  12.  
  13. - (void)tearDown {
  14. [super tearDown];
  15. }
  16.  
  17. - (void)testSanity {
  18. XCTAssert(1 == 1);
  19. }
  20.  
  21. @end

  1. #import <XCTest/XCTest.h>
  2. #import <MagicalRecord/MagicalRecord.h>
  3.  
  4. @interface BadTests : XCTestCase
  5.  
  6. @end
  7.  
  8. @implementation BadTests
  9.  
  10. - (void)setUp {
  11. [super setUp];
  12. NSLog(@"*** USING IN MEMORY STORE ***");
  13. [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelDebug];
  14. [MagicalRecord setupCoreDataStackWithInMemoryStore];
  15. }
  16.  
  17. - (void)tearDown {
  18. [MagicalRecord cleanUp];
  19. [super tearDown];
  20. }
  21.  
  22. - (void)testSanity {
  23. XCTAssert(1 == 1);
  24. }
  25.  
  26. @end

用相同的测试恢复到Xcode 6可以解决问题.

解决方法

结束通过调整我的Podfile解决问题:
  1. link_with 'TestApp','TestAppTests','TestAppUITests'
  2.  
  3. platform :iOS,'8.1'
  4.  
  5. target 'TestApp' do
  6. pod 'MagicalRecord'
  7. end
  8.  
  9. target 'TestApp' do
  10. pod 'OHHTTPStubs'
  11. end

以前我的pod文件看起来像这样:

  1. platform :iOS,'8.1'
  2. pod 'MagicalRecord'
  3. pod 'OHHTTPStubs'

猜你在找的iOS相关文章