终端中没有 NSLog 输出,这些输出来自使用 xcodebuild 运行的测试



我正在尝试在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

我已经查看了XcodeWindow->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(。

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

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

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

最新更新