3

I have two separate targets for Unit Testing and UI Testing in my project besides the main app . These two targets have separate schemes so that i can run them on my CI server separately. I check "Gather Code Coverage" in both of this schemes. Initially i made sure everything is working from XCode by building and running these two schemes separately using "Cmd + U" and coverage data is shown properly for both of these schemes....

In my Jenkins CI i have separate jobs for these two schemes using fastlane, Unit Test scheme is working fine and generating reports. But the UI Test Scheme always shows 0% coverage report no matter what. I don't know what am doing wrong.

Somewhere i read about UI Tests depends on Unit Tests in order for the code coverage, is that true ? If it is true then should i run Unit Tests Before performing UI Tests ?

Thanks in advance.

harsha yarabarla
  • 506
  • 4
  • 11
  • In this SO answer might be a solution related to your issue: https://stackoverflow.com/a/48477190/1418981 – Vlad Jan 27 '18 at 15:21

2 Answers2

2

The previews answer is kind of wrong sir. Even the Xcode shows line coverage due UITests, so of course UITest knows your code, of course it call your code to execute your UI. Only problem is that jenkins is having problem with it since an already known Apple's bug. The gather coverage data debug format have report issues.. Just have a look at the bug's report.

yurisnm
  • 1,630
  • 13
  • 29
-1

But the UI Test Scheme always shows 0% coverage

UI testing doesn't cover any code. It can't see your code. It has never heard of your code. It knows nothing of your code. It has nothing to do with your code! It merely clicks buttons and reads the interface of your app from the outside. In effect, all it can "see" is the screen.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Thanks for the quick reply @matt . Is there any way i can get the View Controllers code coverage then ? How come Xcode able to get this coverage report through "Cmd+U" – harsha yarabarla Jul 12 '16 at 16:22
  • 1
    "Is there any way i can get the View Controllers code coverage" Sure, do a unit test. But when you do a UI test, there is no such thing as a view controller. _There is no app code at all in a UI test._ You're just making me say it over and over. – matt Jul 12 '16 at 16:23
  • got it. Just now saw that UI tests are actually installing "AppUITest" app in the simulator which launches our actual app "App". So as you said it only sees a screen not actual code. – harsha yarabarla Jul 12 '16 at 16:32
  • 3
    it is not true at all. the code covered by uitests should be oncluded to the total coverage indeed. – Bartłomiej Semańczyk Oct 27 '16 at 06:29
  • @BartłomiejSemańczyk no, UI tests run in a different app from your app. You can downvote if you like, but you're still wrong. UI tests are not Unit tests! – matt Oct 27 '16 at 08:39
  • 3
    yes, they are running in different app... but are covered in total coverage. I do it in every project – Bartłomiej Semańczyk Oct 27 '16 at 08:50