2

I want to share data between the Main app target and the XCUITest target. I didn't find any solution. Is dis possible?

rmaddy
  • 307,833
  • 40
  • 508
  • 550
shalu tyagi
  • 148
  • 7

3 Answers3

2

You should be able to accomplish this if you have a shared container between your UITest runner and the app being tested.

See Access App Groups container directory from test runner

ablarg
  • 2,207
  • 1
  • 22
  • 27
  • Writing to/reading from the SIMULATOR_SHARED_RESOURCES_DIRECTORY works for me as of Xcode 12.3. – ryanipete Jan 11 '21 at 01:25
  • yes, but that won't work on a real device. Your UITest will fail because that directory does not exist. – ablarg Jan 22 '21 at 22:56
1

UI Tests are black boxed, so you cant have access to your code.

You can use @testable import in Unit Tests, so full access will be provided. When you're running UITests this is not working, because during a UITest your test class cannot access your app's code.

Please see this for reference: How do I access my swift classes from my UI tests?

-1

Like they already told you in the comments it depends on how is your data is presented.

But usually in your test file, you should import the main module:

import XCTest
@testable import <YOUR_MODULE_NAME>

Your module name is the name of your main Target.

Andrea Miotto
  • 5,998
  • 5
  • 40
  • 64