白盒测试 Jenkins 集成 xctool 执行 iOS 单元测试模拟器无法启动

小明 · 2015年02月08日 · 最后由 Bluelipper 回复于 2016年09月26日 · 2928 次阅读

环境:
Jenkins 搭建在 Mac 服务器上面,安装在 tomcat 当中以 webapp 方式启动。
mac 系统版本:10.9.4
xctool 版本:0.2.2
jenkins 版本:1.598

现象:
在 mac 本机执行测试通过,使用 jenkins shell 方式执行失败,模拟器启动后显示黑屏。

测试命令:
xctool -project Sample.xcodeproj -scheme SampleTests -sdk iphonesimulator test -freshInstall -freshSimulator

错误日志如下:

--------------------------------------------------------------------------------
iOS deployment target '8.1' for architecture 'i386' and variant 'normal' is greater than the maximum value '8.0.99' for the Simulator - iOS 8.0 SDK.
--------------------------------------------------------------------------------
      ~ Write auxiliary files (3 ms)
--------------------------------------------------------------------------------
/bin/mkdir -p /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build
write-file /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/SampleTests-project-headers.hmap
write-file /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/SampleTests-generated-files.hmap
write-file /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/SampleTests-all-target-headers.hmap
write-file /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/SampleTests-own-target-headers.hmap
write-file /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/SampleTests.hmap
write-file /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/SampleTests-all-non-framework-target-headers.hmap
/bin/mkdir -p /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/Objects-normal/i386
write-file /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Intermediates/Sample.build/Debug-iphonesimulator/SampleTests.build/Objects-normal/i386/SampleTests.LinkFileList
--------------------------------------------------------------------------------
      ~ Create product structure (0 ms)
--------------------------------------------------------------------------------
/bin/mkdir -p /Users/wangmy/Library/Developer/Xcode/DerivedData/Sample-haasvciuwqzzcociidumavsvdwoo/Build/Products/Debug-iphonesimulator/SampleTests.xctest
--------------------------------------------------------------------------------
      ~ Process Info.plist (3 ms)
      ~ Compile CSSTests.mm (1461 ms)
      ~ Compile HistoryManageTests.mm (1002 ms)
      ~ Compile RenderTests.mm (1260 ms)
      ~ Compile ERTLuaCoreUnitTests.mm (616 ms)
      ~ Compile ERTCoreTests.mm (346 ms)
      ~ Link SampleTests (30 ms)
      ~ Generate SampleTests.xctest.dSYM (53 ms)
      ~ Touch SampleTests.xctest (2 ms)
      0 errored, 1 warning (1566 ms)


  [Info] Collecting info for testables... (1584 ms)
  run-test SampleTests.xctest (iphonesimulator8.0, application-test)
    [Warning] Tried to install the test host app 'net.light.sample' but failed. (63 ms)
    [Info] Preparing test environment failed; will retry 2 more times (0 ms)
    [Info] Verified iOS Simulators... (0 ms)
    [Info] Shut down iOS Simulator... (0 ms)
    [Info] Stopped any existing iOS simulator jobs to get a fresh simulator. (123 ms)
    [Info] Reset iOS simulator content and settings at path "/Users/wangmy/Library/Developer/CoreSimulator/Devices/2EE9285F-1031-4A63-BE94-F1395C79C083/data" (541 ms)
    [Warning] Tried to install the test host app 'net.light.sample' but failed. (15 ms)
    [Info] Preparing test environment failed; will retry 1 more time (0 ms)
    [Info] Verified iOS Simulators... (0 ms)
    [Info] Shut down iOS Simulator... (0 ms)
    [Info] Stopped any existing iOS simulator jobs to get a fresh simulator. (128 ms)
    [Info] Reset iOS simulator content and settings at path "/Users/wangmy/Library/Developer/CoreSimulator/Devices/2EE9285F-1031-4A63-BE94-F1395C79C083/data" (592 ms)
    [Warning] Tried to install the test host app 'net.light.sample' but failed. (15 ms)
    [Warning] Preparing test environment failed. (0 ms)
      -[TEST_BUNDLE FAILED_TO_START]
--------------------------------------------------------------------------------
There was a problem starting the test bundle: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[TEST_BUNDLE FAILED_TO_START] (0 ms) (0)
      -[CSSTests testCSSCreate]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[CSSTests testCSSCreate] (0 ms) (1)
      -[CSSTests testCSSParser]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[CSSTests testCSSParser] (0 ms) (2)
      -[CSSTests testColorParser]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[CSSTests testColorParser] (0 ms) (3)
      -[CSSTests testPerformanceExample]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[CSSTests testPerformanceExample] (0 ms) (4)
      -[ERTCoreTests testExample]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[ERTCoreTests testExample] (0 ms) (5)
      -[ERTCoreTests testPerformanceExample]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[ERTCoreTests testPerformanceExample] (0 ms) (6)
      -[HistoryManageTests testHistoryManage]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[HistoryManageTests testHistoryManage] (0 ms) (7)
      -[RenderTests testCreateRender]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[RenderTests testCreateRender] (0 ms) (8)
      -[RenderTests testPerformanceExample]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[RenderTests testPerformanceExample] (0 ms) (9)
      -[RenderTests testRenderTree]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[RenderTests testRenderTree] (0 ms) (10)
      -[RenderTests testSetInnerHtml]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
----|---------------------------------------------------------------------------
    X -[RenderTests testSetInnerHtml] (0 ms) (11)
    0 passed, 0 failed, 12 errored, 12 total (1 ms)


Failures:

  0) -[TEST_BUNDLE FAILED_TO_START] (SampleTests.xctest)
--------------------------------------------------------------------------------
There was a problem starting the test bundle: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  1) -[CSSTests testCSSCreate] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  2) -[CSSTests testCSSParser] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  3) -[CSSTests testColorParser] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  4) -[CSSTests testPerformanceExample] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  5) -[ERTCoreTests testExample] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  6) -[ERTCoreTests testPerformanceExample] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  7) -[HistoryManageTests testHistoryManage] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  8) -[RenderTests testCreateRender] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  9) -[RenderTests testPerformanceExample] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  10) -[RenderTests testRenderTree] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

  11) -[RenderTests testSetInnerHtml] (SampleTests.xctest)
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.
--------------------------------------------------------------------------------

** TEST FAILED: 0 passed, 0 failed, 12 errored, 12 total ** (77259 ms)
共收到 15 条回复 时间 点赞

不太懂 ios 测试,但是你上面的出错信息说的是你的应用没有安装

Tried to install the test host app 'net.light.sample' but failed
小明 #14 · 2015年02月08日 Author

#1 楼 @doctorq 本地执行是可通过的,就是能启动模拟器执行测试的,但是通过 ssh 和 jenkins 就会失败。

#2 楼 @mingyuwang 这个不能这么暗示自己,不是说一次执行成功,就说明它应该成功,这就是 bug 存在的原因。感觉是你的远程集成环境中启动模拟器没弄好,既然知道原因,可以仔细检查下。

小明 #12 · 2015年02月08日 Author

#3 楼 @doctorq 不是这个意思,是在 mac 本地执行是一直通过的,但是通过 ssh 和 jenkins 是一直不通过,两种情况下的结果不同。主要想问一下有没有人碰到类似的问题,有没有什么解决的思路。

锅锅,你版本不兼容啊,你仔细读下第一句。iOS deployment target '8.1' for architecture 'i386' and variant 'normal' is greater than the maximum value '8.0.99' for the Simulator - iOS 8.0 SDK.

会不会是由于 jenkins 里面使用的用户不一样?用户不一样会导致各种设置不一样的。我在 windows 下用 jenkins 经常遇到这个问题,本地跑得好好的脚本去到 jenkins 各种报错。但 mac 里面没用过,不是很清楚是不是也是一样的。

#6 楼 @beerbox No,版本不兼容的话,本地是运行不起来的

#7 楼 @chenhengjie123 用户和本地使用的是相同的,都是管理员用户

@mingyuwangxctool找到一段说明
In order to your run your tests within a continuous integration environment, you must create Shared Schemes for your application target and ensure that all dependencies (such as CocoaPods) are added explicitly to the Scheme
这一部分有做了吗?

小明 #11 · 2015年02月09日 Author

#10 楼 @chenhengjie123 有做 Shared Schemes ,这个是 xcode 里面配置好的,直接获取源码就有

@mingyuwang 能把正常跑得通的 log 贴上来一下吗?到

----|---------------------------------------------------------------------------
    X -[TEST_BUNDLE FAILED_TO_START] (0 ms) (0)
      -[CSSTests testCSSCreate]
--------------------------------------------------------------------------------
Test did not run: Simulator 'iPhone 4s' was not prepared: Failed for unknown reason.

这里就可以了。
估计还是因为 jenkins 建立的 shell 和你能执行成功的 shell 部分配置不一样。

#12 楼 @chenhengjie123 执行正常的 shell 输出:

[Info] Collecting info for testables... (1402 ms)
  run-test SampleTests.xctest (iphonesimulator8.0, application-test)
    [Info] Verified iOS Simulators... (0 ms)
    [Info] Shut down iOS Simulator... (273 ms)
    [Info] Stopped any existing iOS simulator jobs to get a fresh simulator. (125 ms)
    [Info] Uninstalled 'net.light.sample' to get a fresh install. (2866 ms)
    [Info] Installed 'net.light.sample'. (881 ms)
    [Info] Launching test host and running tests ... (0 ms)

#12 楼 @chenhengjie123

✓ -[RenderTests testSetInnerHtml] (1 ms)
    11 passed, 0 failed, 0 errored, 11 total (845 ms)

@mingyuwang have you fixed? I have just met the same problem :(

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册