Question

I have Jenkins with the Xcode plugin configured to run unit tests by adding the test build action to the Custom xcodebuild arguments setting. For more information on getting Jenkins to run the unit tests at all with Xcode 5, see this question.

Now that I have it running, it seems to mix console output from NSLog statements or the final ** TEST SUCCEEDED ** message with the test results, thus occasionally tripping up the parser that converts unit test results to the JUnit format required for Jenkins.

For example, the Jenkins log shows output like this:

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

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

when it should actually be:

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

I have looked into this further and pulled Jenkins out of the picture. If I run the xcodebuild command directly at the command prompt:

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

the output always comes out fine, in-order.

If, however, I pipe the output to another program or redirect to a file:

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

The output is out-of-order as described above.

Could this be due to buffering or lack of buffering when not directly writing to stdout? Does anyone know why this is happening and any workaround I might be able to perform to fix it?

Was it helpful?

Solution 2

Thanks to this answer, I discovered a way to essentially disable buffering using the script command.

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

OTHER TIPS

As noted by Malte in a comment above, a cleaner solution might be

    env NSUnbufferedIO=YES xcodebuild ...
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top