2

I created a new UI Test Target to try out the new XCode 7 UI tests. Aside from recording some steps, I also want to run some of my code inside the tests such as Utils class to test for some cases etc and take different paths in the test.

Is there a way to make all my project files and libraries included in this new UI Test Target ? I can make sure that my source files are include this UI Test Target from the Target Membership checkbox but that would mean that I would have to go through all my files and manually check that box?

Also, how does it work with the UIKit Framework? I need my tests to be able to find UIScreen class for instance.

m.y
  • 691
  • 9
  • 21
  • Sounds like Unit Tests are more what you are searching for. – dasdom Dec 07 '15 at 12:03
  • I've set up the UI Tests to take screenshots actually (using fastlane snapshot) – m.y Dec 07 '15 at 12:11
  • That's fine. But if you want to access the modules on code layer Unit Tests are more suitable. – dasdom Dec 07 '15 at 13:04
  • Yeah, but i can only get fastlane snapshot to work in tandem with UI tests – m.y Dec 07 '15 at 13:48
  • So? You can have Unit Tests **and** UI Tests in the same project. – dasdom Dec 07 '15 at 13:49
  • yes i created two different targets/configurations? and i've set both to have the Target Dependencies on my app target. I'd like to access my code layer in a UI test so that I can take a snapshot. – m.y Dec 07 '15 at 13:52
  • You don't need access to your code to take a screenshot. I still don't understand your problem. – dasdom Dec 07 '15 at 14:18
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/97205/discussion-between-m-y-and-dasdom). – m.y Dec 07 '15 at 14:37

1 Answers1

1

Using the new UI automation framework Apple introduced in WWDC 15 it is not possible to access your app's code from the UI-Automation test. It's meant to simulate what a user would have access too, which can be frustrating at times.

The UI tests are a separate module from the app, therefore not run inside your app as a logic test would. The only way for them to share code is to compile in all the app files you need to share between the two modules. Hope that helps.

cakes88
  • 1,857
  • 5
  • 24
  • 33
  • Small exception: You can interact with the app when it launches in UITests. ref https://stackoverflow.com/a/58616797/5389500 – Sentry.co Mar 28 '23 at 02:28