加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ios – 在使用Cocoapods的项目中执行单元测试时,“类X都在两者中

发布时间:2020-12-14 19:37:36 所属栏目:百科 来源:网络整理
导读:我为使用 Cocoapods的现有项目添加了一个单元测试目标. 当我开始测试它运行iOS模拟器时,我在Xcode的控制台上发出了一堆警告: Class PodsDummy_Pods is implemented in both /Users/me/Library/Developer/CoreSimulator/Devices/604372F1-E934-445C-B8F6-3D8
我为使用 Cocoapods的现有项目添加了一个单元测试目标.

当我开始测试它运行iOS模拟器时,我在Xcode的控制台上发出了一堆警告:

Class PodsDummy_Pods is implemented in both
/Users/me/Library/Developer/CoreSimulator/Devices/604372F1-E934-445C-B8F6-3D8C86AA8E41/data/Containers/Bundle/Application/2A1BCAE6-5127-4288-B0E7-15588A1C09D1/MyAPP..app/MyApp.
and
/Users/me/Library/Developer/Xcode/DerivedData/MyApp-fzjqljiyaapspvaylhszcbkhtijd/Build/Products/Debug-iphonesimulator/MyAppTests.xctest/MyAppTests.
One of the two will be used. Which one is undefined.

对于我的项目使用的窗格中包含的每个类,都会显示此错误消息.

最后,该项目抛出一个EXC_BAD_ACCESS

当我在Xcode的控制台中输入bt时,这个错误就像一个无限循环:

frame #130498: 0x000000012626e897
MyAppTests`___lldb_unnamed_function42$$MyAppTests + 135

有什么建议吗?

解决方法

终于找到了解决这个问题的方法!在我这边,我的swift框架单元测试存在这个问题.我的Podfile看起来像这样:

def import_gtm
  send :pod,'GoogleTagManager','~> 5.0.8'
end

target 'MyFramework' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyFramework
  import_gtm
end

target 'MyFrameworkTests' do
  use_frameworks!

  # Pods for testing
end

虽然我的测试正确执行,但我有大量的日志,就像OP一样.在阅读了这个Github issue后,我更改了我的Podfile以获取以下内容:

def import_gtm
  send :pod,'~> 5.0.8'
end

target 'MyFramework' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!

  # Pods for MyFramework
  import_gtm

  target 'MyFrameworkTests' do
    inherit! :search_paths
  end
end

我终于摆脱了所有这些警告日志!尝试在重建之前清理(cmd alt shift K)或删除DerivedData文件夹内容:

rm -rf ~/Library/Developer/Xcode/DerivedData/*

我希望这有帮助 !

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读