【问题标题】:No NSLog output in terminal from tests run with xcodebuild使用 xcodebuild 运行的测试在终端中没有 NSLog 输出
【发布时间】:2018-11-17 04:51:29
【问题描述】:

我正在尝试在 ios 上实现 CI。我在真实设备(iPad)上使用 xcodebuild 从命令行运行 xcode 单元测试:

xcodebuild test -project MyProject.xcodeproj -scheme tests DEVELOPMENT_TEAM={DEV_TEAM_ID} -destination platform=iOS,id={DEVICE_UUID} build-for-testing -allowProvisioningUpdates -configuration {Debug/Release}

我有一个单元测试,其中包含 NSLog 调用。问题是这些日志没有显示在调用 xcodebuild 的终端窗口中:

Test Suite 'Selected tests' started at 2018-06-07 05:10:45.653
Test Suite 'XcodeTests.xctest' started at 2018-06-07 05:10:45.655
Test Suite 'XcodeTests.xctest' failed at 2018-06-07 05:10:45.655.
        Executed 1 test, with 1 failure (0 unexpected) in 0.000 (0.00) seconds
Test Suite 'Selected tests' failed at 2018-06-07 05:10:45.656.
        Executed 1 test, with 1 failure (0 unexpected in 0.00 (0.003) seconds

我查看了 Xcode 的 Window->Devices and Simulators-> View Device Logs 中的设备日志,看起来它们在那里,但作为通知(也许它们是通知的事实很重要):

Jun  7 05:10:45 MyiPad tests(XcodeTests)[21982] <Notice>: ENTERED TEST
Jun  7 05:10:45 MyiPad tests[21982] <Notice>: CREATED EXPECTATIONS

我已经在另一台连接了 iPad 的 Mac 上测试了这种启动方法,它的效果很奇怪。用于在终端中显示 NSLog 消息的机器的配置如下:

 System Software Overview:

 System Version: macOS 10.13.2 (17C88)
 Kernel Version: Darwin 17.3.0
 Boot Volume: SYSTEM
 Boot Mode: Normal
 Computer Name: Mac001
 User Name: MacUser001
 Secure Virtual Memory: Enabled
 System Integrity Protection: Enabled
 Time since boot: 7 days 48 minutes

 XCODE VERSION DETAILS: 
 Xcode 9.2
 Build version 9C40b

 Device iOS Version: 11.2 (15C114)

在终端中不显示 NSLogs 的其他配置如下:

System Software Overview:

System Version: macOS 10.13.3 (17D47)
Kernel Version: Darwin 17.4.0
Boot Volume: SYSTEM
Boot Mode: Normal
Computer Name: Mac002
User Name: MacUser002
Secure Virtual Memory: Enabled
System Integrity Protection: Enabled
Time since boot: 7 days 48 minutes

XCODE VERSION DETAILS: 
Xcode 9.2
Build version 9C40b

Device iOS Version: 10.2 (14C92)

可能是什么问题?它可能来自设备或mac工作站吗? (我对其中任何一个都没有物理访问权限,只能远程访问 mac)。

【问题讨论】:

  • 我遇到了同样的问题。最后,我使用 printf 代替 NSLog。 printf 很适合我。

标签: ios terminal continuous-integration xctest xcodebuild


【解决方案1】:

就像 Dan 说的,如果你想在控制台上看到你的测试消息,你最好使用 printf 而不是 NSLog

例如printf("%s", [yourNSString UTF8String]);

【讨论】:

    【解决方案2】:

    确实对于 iOS 10+ 版本,看起来 NSLog 被视为 消息,并且不包含在 xcodebuild 输出的 stdout 或 stderr 中。我通过查看设备控制台日志发现了这一点。 我找到了devliubo前段时间提到的解决方案,但我不确定这是否是一个常见问题(感谢devliubo)。 使用 printf 而不是 NSLog 是打印这种特殊情况的消息的唯一方法。

    【讨论】:

      猜你喜欢
      • 2016-05-15
      • 2016-02-15
      • 1970-01-01
      • 2010-10-09
      • 1970-01-01
      • 2020-08-03
      • 2014-12-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多