【问题标题】:xcodebuild corrupts test result output when output redirected to file当输出重定向到文件时,xcodebuild 会损坏测试结果输出
【发布时间】:2013-09-30 11:17:42
【问题描述】:

我将 Jenkins 与 Xcode 插件配置为通过将测试构建操作添加到自定义 xcodebuild 参数设置来运行单元测试。有关让 Jenkins 使用 Xcode 5 运行单元测试的更多信息,请参阅question

现在我让它运行了,它似乎将来自 NSLog 语句或最终 ** TEST SUCCEEDED ** 消息的控制台输出与测试结果混合在一起,因此偶尔会导致将单元测试结果转换为 Jenkins 所需的 JUnit 格式的解析器出错。

例如,Jenkins 日志显示如下输出:

Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsNotZero]' passed (** TEST SUCCEEDED **

0.000 seconds).
Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsZero]' started.

什么时候应该是:

Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsNotZero]' passed (0.000 seconds).
Test Case '-[Redacted_Conversion_Tests testConvertTo_ShouldSetamount_WhenamountIsZero]' started.
** TEST SUCCEEDED **

我对此进行了进一步调查,并将詹金斯从图片中拉了出来。如果我直接在命令提示符下运行 xcodebuild 命令:

xcodebuild \
    -workspace project.xcworkspace \
    -scheme Tests \
    -configuration Release \
    -sdk iphonesimulator7.0 \
    -destination "platform=iOS Simulator,name=iPhone Retina (4-inch),OS=latest" \
    test

输出总是井井有条。

但是,如果我将输出通过管道传输到另一个程序或重定向到一个文件:

xcodebuild \
    -workspace project.xcworkspace \
    -scheme Tests \
    -configuration Release \
    -sdk iphonesimulator7.0 \
    -destination "platform=iOS Simulator,name=iPhone Retina (4-inch),OS=latest" \
    test > xcodebuild.out
cat xcodebuild.out

如上所述,输出是无序的。

这可能是由于不直接写入标准输出时缓冲或缺乏缓冲造成的吗?有谁知道为什么会发生这种情况以及我可以执行的任何解决方法来解决它吗?

【问题讨论】:

  • 您使用什么解析器将输出更改为 junit 测试结果?

标签: xcode unit-testing pipe xcode5 xcodebuild


【解决方案1】:

感谢answer,我发现了一种使用script 命令基本上禁用缓冲的方法。

script -q -t 0 xcodebuild.out \
    xcodebuild \
        -workspace project.xcworkspace \
        -scheme Tests \
        -configuration Release \
        -sdk iphonesimulator7.0 \
        -destination "platform=iOS Simulator,name=iPhone Retina (4-inch),OS=latest" \
        test
cat xcodebuild.out

【讨论】:

  • 如果你正在管道到另一个命令 cough ocunit2junit cough 然后 ``` script -q /dev/null xcodebuild ... | ocunit2junit ``` 会工作
  • 游戏迟到了,但另一种方法是使用env NSUnbufferedIO=YES xcodebuild ...。在 Yosemite 和 Xcode 7 上测试。
【解决方案2】:

正如Malte 在上面的评论中所指出的,一个更清洁的解决方案可能是

    env NSUnbufferedIO=YES xcodebuild ...

【讨论】:

  • 这才是真正的解决方案
猜你喜欢
  • 2017-05-13
  • 2014-01-09
  • 1970-01-01
  • 2022-01-03
  • 1970-01-01
  • 1970-01-01
  • 2013-05-27
  • 2020-06-02
  • 1970-01-01
相关资源
最近更新 更多