具有代码覆盖率的UIAutomation [英] UIAutomation with code coverage

查看:94
本文介绍了具有代码覆盖率的UIAutomation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用jenkins自动进行iOS测试。到目前为止,我没有遇到运行单元测试,将OCUnit转换为JUnit并以Cobertura格式生成代码覆盖(大量谷歌搜索但没有硬问题)的问题。

I am currently automating our iOS testing on jenkins. So far I had no problems with running unit tests, converting OCUnit into JUnit and generating code coverage in Cobertura format (lots of googling but no hard problems).

然而,当创建UIAutomation工作,我被卡住了。测试成功运行(从命令行调用 instruments )。生成junit报告很棘手,但可能。
问题是当运行UIAutomation时,不会生成代码覆盖文件。

However, when creating UIAutomation job, I am stuck. The tests are running successfully (calling instruments from command line). Generating junit report was tricky but possible. The problem is that when running UIAutomation, no code coverage files are generated.

是否有可能生成它们?如果没有,你能解释一下原因吗?

Is there a possibility to generate them? If not, could you please explain why?

到目前为止我尝试了什么:

What I tried so far:


  1. 将UIAutomation附加到iOS模拟器上已经运行的应用程序。

    • 这似乎不可能。正在运行的应用程序被仪器杀死并重新启动新实例或打印出一个神秘的错误消息。


  • 申请优雅地结束但没有生成保险。

编辑
使用不同的框架进行一些测试后,我意识到退出模拟器是不够的,你必须明确地调用 exit()来自应用程序的。使用UI自动化这有点棘手,但您可以声明一个应用程序,例如, my-app:// exit 并使用 UIAHost.performTaskWithPathArgumentsTimeout 通过MobileSafari调用它。将检查这是否足以生成文件。

Edit After some testing with a different framework I realized it's not enough to quit the simulator, you have to explicitely call exit() from the application. With UI Automation this is a bit tricky but you can declare an applicaton scheme, e.g. my-app://exit and call it through MobileSafari using UIAHost.performTaskWithPathArgumentsTimeout. Will check whether this is enough for the files to be generated.

推荐答案

按照这些步骤,我能够生成代码覆盖率来自UI Automation的文件,并通过cobertura Jenkins插件显示信息。

Following these steps, I was able to generate the code coverage files from UI Automation and display the information through the cobertura Jenkins plugin.

首先将生成测试覆盖率文件和仪器程序流程构建设置设置为是。每次在模拟器中运行应用程序并退出应用程序时,这将生成代码覆盖文件。在Info.plist文件中添加UIApplicationExitsOnSuspend并将此选项设置为YES。运行UI自动化测试,在结束时,您可以通过手动按下模拟器中的HOME按钮或使用UIATarget.localTarget()。deactivateAppForDuration()方法退出应用程序。请注意,如果您的应用程序具有依赖于deactivateAppForDuration()方法的任何UI自动化测试,则测试将在运行命令时终止。

First set the "Generate Test Coverage Files" and "Instrument Program Flow" build settings to Yes. This will generate code coverage files every time you run your application in the simulator and exit the application. Add UIApplicationExitsOnSuspend in your Info.plist file and set this option to 'YES'. Run the UI automation test and at the end of it you can exit the app either by manually pressing the HOME button in the simulator or using the UIATarget.localTarget().deactivateAppForDuration() method. Note if your app has any UI Automation tests that rely on the deactivateAppForDuration() method, the tests will terminate upon running the command.

获得gcda文件后即可通过下载gcovr生成cobertura xml文件( https://software.sandia.gov/trac/ fast / wiki / gcovr )并运行命令

Once you have the gcda files you can generate the cobertura xml file by downloading gcovr (https://software.sandia.gov/trac/fast/wiki/gcovr) and running the command

gcovr -r your_root_directory --object-directory path_to_gcda_files --xml> coverage.xml

gcovr -r your_root_directory --object-directory path_to_gcda_files --xml > coverage.xml

您可以设置Jenkins cobertura插件以根据需要显示信息。

With that you can setup the Jenkins cobertura plugin to display the information as needed.

来源: http://blog.octo.com/en/jenkins-quality-dashboard- ios-development /#step2-2

这篇关于具有代码覆盖率的UIAutomation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆