UIAutomation with code coverage

前端 未结 2 1880
我在风中等你
我在风中等你 2021-02-06 09:01

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 fo

相关标签:
2条回答
  • 2021-02-06 09:13

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

    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.

    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

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

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

    0 讨论(0)
  • 2021-02-06 09:28

    From my understanding code coverage files get generated when the app quits, but you can't just kill the simulator.

    Have you tried creating a separate target for your app where you have the info.plist property "UIApplicationExitsOnSuspend" set to true?

    There is a slightly wider problem, however. The generated coverage files aren't cumulative and get overwritten each time the application quits. So, depending on how your tests are structured (i.e. are you killing and starting the app for each distinct test) then you may struggle to get decent code coverage.

    0 讨论(0)
提交回复
热议问题