CocoaLumberJack XCTest链接器运行测试用例时出错

时间:2014-09-24 16:23:59

标签: ios xctest lumberjack

当使用带有XCTest的CocoaLumberJack时,我收到一个错误,它无法找到DDLog.h。我试过把它改成<CocoaLumberjack/DDLog.h>而没有运气。该项目在iOS模拟器中使用LumberJack进行编译和运行,但是当我为单元测试目标运行它时,我得到了这个错误(见截图)。

这是我的-Prefix.pch

  #import <Availability.h>

  #ifndef __IPHONE_5_0
  #warning "This project uses features only available in iOS SDK 5.0 and later."
  #endif

  #ifdef __OBJC__
      #import <UIKit/UIKit.h>
      #import <Foundation/Foundation.h>
      #import <CoreData/CoreData.h>
      #import <CocoaLumberjack/DDLog.h>
      #import "Utilities.h"
  #endif


  #ifdef DEBUG
  static const int ddLogLevel = LOG_LEVEL_VERBOSE;
  #else
  static const int ddLogLevel = LOG_LEVEL_ERROR;
  #endif

错误:

Error

我已将库与tests目标相关联,如下所示libPods.a

Linked Libraries

为什么运行TestCases时LumberJack不能正确链接?我还需要添加一些其他内容才能正确链接到TestTarget吗?

2 个答案:

答案 0 :(得分:1)

我能够通过删除-Prefix.pch文件的自定义项并重新格式化podfile以使用目标来解决此问题。我不得不移动

 #import "DDLog.h"

#ifdef DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_ERROR;
#endif

进入`Utility.h&#39;类。

重建podfile以链接两个目标:

platform :ios, '7.0'

def common_pods
    pod 'CocoaLumberjack'
    pod 'HexColors'
end

target :MyApp do
    common_pods
end

target :MyAppTests do
    common_pods
end

我还必须从两个目标中移除libPods.a,因为它将不再构建。相反,libPods-MyApp.alibPods-MyAppTests.a是使用新的podfile配置构建的。

答案 1 :(得分:0)

您必须在项目中启用Pods配置→项目设置→信息→配置:

https://stackoverflow.com/a/17850444/511878